35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { auth } from './lib/auth'
|
|
import { PrismaClient } from '@prisma/client'
|
|
|
|
const prisma = new PrismaClient()
|
|
|
|
async function seed() {
|
|
console.log('Cleaning up existing superadmin if exists...')
|
|
// Delete the existing user to avoid constraints
|
|
await prisma.user.deleteMany({
|
|
where: { email: 'superadmin@innungsapp.de' },
|
|
})
|
|
|
|
console.log('Seeding superadmin via better-auth API...')
|
|
|
|
try {
|
|
const user = await auth.api.signUpEmail({
|
|
body: {
|
|
email: 'superadmin@innungsapp.de',
|
|
password: 'demo1234',
|
|
name: 'Super Admin',
|
|
}
|
|
})
|
|
|
|
// Check if better-auth actually uses the Prisma DB directly here
|
|
// It should, as auth is configured with the prisma instance
|
|
console.log('Superadmin created successfully! ID:', user.user.id)
|
|
} catch (err: any) {
|
|
console.error('Error creating superadmin:', err.message || err)
|
|
}
|
|
}
|
|
|
|
seed()
|
|
.catch(console.error)
|
|
.finally(() => prisma.$disconnect())
|