123df671f5
Reviewed-on: #5 Co-authored-by: David Gwilliam <dhgwilliam@gmail.com> Co-committed-by: David Gwilliam <dhgwilliam@gmail.com>
59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
const { PrismaClient } = require('@prisma/client');
|
|
const bcrypt = require('bcryptjs');
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
try {
|
|
// Hash password using bcrypt (Better Auth compatible)
|
|
const password = 'admin';
|
|
const salt = await bcrypt.genSalt(12);
|
|
const passwordHash = await bcrypt.hash(password, salt);
|
|
|
|
// Generate cuid-like ID
|
|
const cuid = `clx_${Date.now()}_${Math.random().toString(36).substring(2, 8)}`;
|
|
|
|
// Check if user exists
|
|
const existing = await prisma.user.findUnique({
|
|
where: { email: 'david@dhg.lol' }
|
|
});
|
|
|
|
if (existing) {
|
|
await prisma.user.delete({ where: { id: existing.id } });
|
|
console.log('🗑️ Deleted existing user');
|
|
}
|
|
|
|
// Create admin user with Better Auth compatible password hash
|
|
const user = await prisma.user.create({
|
|
data: {
|
|
id: cuid,
|
|
email: 'david@dhg.lol',
|
|
emailVerified: true,
|
|
role: 'club_admin',
|
|
name: 'David Admin',
|
|
accounts: {
|
|
create: {
|
|
id: `${cuid}_acc`,
|
|
accountId: `${cuid}_acc`,
|
|
providerId: 'credential',
|
|
password: passwordHash, // bcrypt hash
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
console.log('✅ Admin user created successfully!');
|
|
console.log(' Email:', user.email);
|
|
console.log(' Role:', user.role);
|
|
console.log(' Password: admin');
|
|
console.log(' Name:', user.name);
|
|
|
|
} catch (error) {
|
|
console.error('❌ Error:', error.message);
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
main();
|