40 lines
952 B
JavaScript
40 lines
952 B
JavaScript
const bcrypt = require('bcrypt')
|
|
const prisma = require('../config/prisma')
|
|
|
|
async function createAdmin() {
|
|
const email = 'admin@thetiptop.fr'
|
|
const password = 'Admin@TipTop2026!'
|
|
|
|
const existing = await prisma.user.findUnique({ where: { email } })
|
|
|
|
if (existing) {
|
|
await prisma.user.update({
|
|
where: { email },
|
|
data: { isEmailVerified: true, role: 'ADMIN' },
|
|
})
|
|
console.log('Admin mis à jour :', email)
|
|
return
|
|
}
|
|
|
|
const hashed = await bcrypt.hash(password, 10)
|
|
|
|
await prisma.user.create({
|
|
data: {
|
|
firstname: 'Admin',
|
|
lastname: 'TipTop',
|
|
email,
|
|
password: hashed,
|
|
role: 'ADMIN',
|
|
isEmailVerified: true,
|
|
},
|
|
})
|
|
|
|
console.log('Admin créé avec succès')
|
|
console.log(' Email :', email)
|
|
console.log(' Mot de passe:', password)
|
|
}
|
|
|
|
createAdmin()
|
|
.catch((e) => { console.error('Erreur :', e.message); process.exit(1) })
|
|
.finally(() => prisma.$disconnect())
|