Postgres
This commit is contained in:
@@ -13,27 +13,55 @@ async function hashPassword(password: string): Promise<string> {
|
||||
return `${salt}:${key.toString('hex')}`
|
||||
}
|
||||
|
||||
function getEnv(name: string): string {
|
||||
return (process.env[name] ?? '').trim()
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('Seeding superadmin...')
|
||||
const hash = await hashPassword('demo1234')
|
||||
console.log('Hash generated.')
|
||||
const email = getEnv('SUPERADMIN_EMAIL').toLowerCase() || 'superadmin@innungsapp.de'
|
||||
const name = getEnv('SUPERADMIN_NAME') || 'Super Admin'
|
||||
const userId = getEnv('SUPERADMIN_USER_ID') || 'superadmin-user-id'
|
||||
const accountId = getEnv('SUPERADMIN_ACCOUNT_ID') || 'superadmin-account-id'
|
||||
|
||||
let password = getEnv('SUPERADMIN_PASSWORD')
|
||||
if (!password) {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
throw new Error('SUPERADMIN_PASSWORD must be set in production.')
|
||||
}
|
||||
|
||||
password = 'demo1234'
|
||||
console.warn('SUPERADMIN_PASSWORD not set. Using development fallback password.')
|
||||
}
|
||||
|
||||
console.log(`Seeding superadmin user for ${email}...`)
|
||||
const hash = await hashPassword(password)
|
||||
|
||||
const superAdminUser = await prisma.user.upsert({
|
||||
where: { email: 'superadmin@innungsapp.de' },
|
||||
update: {},
|
||||
create: {
|
||||
id: 'superadmin-user-id',
|
||||
name: 'Super Admin',
|
||||
email: 'superadmin@innungsapp.de',
|
||||
where: { email },
|
||||
update: {
|
||||
name,
|
||||
emailVerified: true,
|
||||
role: 'admin',
|
||||
},
|
||||
create: {
|
||||
id: userId,
|
||||
name,
|
||||
email,
|
||||
emailVerified: true,
|
||||
role: 'admin',
|
||||
},
|
||||
})
|
||||
|
||||
await prisma.account.upsert({
|
||||
where: { id: 'superadmin-account-id' },
|
||||
update: { password: hash },
|
||||
where: { id: accountId },
|
||||
update: {
|
||||
accountId: superAdminUser.id,
|
||||
userId: superAdminUser.id,
|
||||
providerId: 'credential',
|
||||
password: hash,
|
||||
},
|
||||
create: {
|
||||
id: 'superadmin-account-id',
|
||||
id: accountId,
|
||||
accountId: superAdminUser.id,
|
||||
providerId: 'credential',
|
||||
userId: superAdminUser.id,
|
||||
@@ -41,7 +69,7 @@ async function main() {
|
||||
},
|
||||
})
|
||||
|
||||
console.log('Done! Login: superadmin@innungsapp.de / demo1234')
|
||||
console.log(`Done. Login: ${email} / ${password}`)
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user