add admin creation to deployment
Build & Push / Pipeline Tests (push) Successful in 1m52s
Test / Type Check (all packages) (push) Successful in 52s
Build & Push / Build & Push Docker Image (push) Successful in 25s
Test / API Unit Tests (push) Successful in 1m6s
Test / Homepage Unit Tests (push) Successful in 45s
Test / Carplace Unit Tests (push) Successful in 44s
Test / Admin Unit Tests (push) Successful in 42s
Test / Dashboard Unit Tests (push) Successful in 42s
Test / API Integration Tests (push) Successful in 1m7s
Build & Push / Pipeline Tests (push) Successful in 1m52s
Test / Type Check (all packages) (push) Successful in 52s
Build & Push / Build & Push Docker Image (push) Successful in 25s
Test / API Unit Tests (push) Successful in 1m6s
Test / Homepage Unit Tests (push) Successful in 45s
Test / Carplace Unit Tests (push) Successful in 44s
Test / Admin Unit Tests (push) Successful in 42s
Test / Dashboard Unit Tests (push) Successful in 42s
Test / API Integration Tests (push) Successful in 1m7s
This commit is contained in:
@@ -40,24 +40,33 @@ async function main() {
|
||||
normalizeDatabaseUrlForExecution()
|
||||
|
||||
const email = requireValue('email', 'ADMIN_EMAIL').toLowerCase()
|
||||
const password = requireValue('password', 'ADMIN_PASSWORD')
|
||||
const firstName = readValue('first-name', 'ADMIN_FIRST_NAME', 'Admin').trim()
|
||||
const lastName = readValue('last-name', 'ADMIN_LAST_NAME', 'User').trim()
|
||||
const role = readValue('role', 'ADMIN_ROLE', 'SUPER_ADMIN').trim().toUpperCase()
|
||||
const updateExisting = readBoolean('update-existing', 'ADMIN_UPDATE_EXISTING', false)
|
||||
|
||||
if (!ADMIN_ROLES.has(role)) {
|
||||
throw new Error(`Invalid ADMIN_ROLE "${role}". Use one of: ${Array.from(ADMIN_ROLES).join(', ')}`)
|
||||
}
|
||||
|
||||
if (password.length < 8) {
|
||||
throw new Error('Admin password must be at least 8 characters long.')
|
||||
}
|
||||
const checkOnly = process.argv.includes('--check')
|
||||
|
||||
const { PrismaClient } = require('../packages/database/generated')
|
||||
const prisma = new PrismaClient()
|
||||
try {
|
||||
const existing = await prisma.adminUser.findUnique({ where: { email } })
|
||||
|
||||
if (checkOnly) {
|
||||
console.log(existing ? 'EXISTS' : 'MISSING')
|
||||
process.exitCode = existing ? 0 : 1
|
||||
return
|
||||
}
|
||||
|
||||
const password = requireValue('password', 'ADMIN_PASSWORD')
|
||||
const firstName = readValue('first-name', 'ADMIN_FIRST_NAME', 'Admin').trim()
|
||||
const lastName = readValue('last-name', 'ADMIN_LAST_NAME', 'User').trim()
|
||||
const role = readValue('role', 'ADMIN_ROLE', 'SUPER_ADMIN').trim().toUpperCase()
|
||||
const updateExisting = readBoolean('update-existing', 'ADMIN_UPDATE_EXISTING', false)
|
||||
|
||||
if (!ADMIN_ROLES.has(role)) {
|
||||
throw new Error(`Invalid ADMIN_ROLE "${role}". Use one of: ${Array.from(ADMIN_ROLES).join(', ')}`)
|
||||
}
|
||||
|
||||
if (password.length < 8) {
|
||||
throw new Error('Admin password must be at least 8 characters long.')
|
||||
}
|
||||
|
||||
const passwordHash = await bcrypt.hash(password, 12)
|
||||
|
||||
if (existing) {
|
||||
|
||||
Reference in New Issue
Block a user