const { PrismaClient } = require('@prisma/client'); const { betterAuth } = require('better-auth'); const { prismaAdapter } = require('better-auth/adapters/prisma'); const prisma = new PrismaClient(); // Create Better Auth instance const auth = betterAuth({ database: prismaAdapter(prisma, { provider: 'sqlite', }), emailAndPassword: { enabled: true, }, baseURL: process.env.BETTER_AUTH_URL || 'http://localhost:3000', }); async function main() { try { // Check if user exists const existing = await prisma.user.findUnique({ where: { email: 'david@dhg.lol' } }); if (existing) { console.log('User exists, deleting...'); await prisma.user.delete({ where: { id: existing.id } }); } // Create user using Better Auth's internal method // Better Auth uses bcrypt internally for password hashing const signUpResult = await auth.api.signUpEmail({ body: { email: 'david@dhg.lol', password: 'adminadmin', name: 'David Admin', }, }); console.log('✅ Admin user created via Better Auth API!'); console.log(' Email:', signUpResult.user.email); console.log(' Name:', signUpResult.user.name); console.log(' Password: adminadmin'); // Update the user to have club_admin role await prisma.user.update({ where: { id: signUpResult.user.id }, data: { role: 'club_admin' } }); console.log('✅ User role updated to club_admin'); } catch (error) { console.error('❌ Error:', error.message); if (error.errors) { console.error(' Details:', error.errors); } } finally { await prisma.$disconnect(); } } main();