fix: update documentation and configuration files

This commit is contained in:
2026-03-29 19:26:50 -07:00
parent 00aa8cf044
commit 26d9c7e79e
50 changed files with 6264 additions and 2627 deletions
+58
View File
@@ -0,0 +1,58 @@
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();
+63
View File
@@ -0,0 +1,63 @@
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();
+56
View File
@@ -0,0 +1,56 @@
const { PrismaClient } = require('@prisma/client');
const crypto = require('crypto');
const prisma = new PrismaClient();
async function main() {
try {
// Use built-in crypto for quick hash (we'll update with proper one after)
const salt = crypto.randomBytes(16).toString('hex');
const hash = crypto.pbkdf2Sync('admin', salt, 10000, 64, 'sha256').toString('hex');
const fullHash = `${salt}:${hash}`;
// 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 } });
}
// Create admin user
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: fullHash,
}
}
}
});
console.log('✅ Admin user created successfully!');
console.log(' Email:', user.email);
console.log(' Role:', user.role);
console.log(' Password: admin');
} catch (error) {
console.error('❌ Error:', error.message);
} finally {
await prisma.$disconnect();
}
}
main();
+35
View File
@@ -0,0 +1,35 @@
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
async function listUsers() {
try {
const users = await prisma.user.findMany({
include: {
player: true,
},
orderBy: {
id: 'asc',
},
});
console.log('Users in database:');
console.log('='.repeat(80));
users.forEach(user => {
console.log(`ID: ${user.id}`);
console.log(` Email: ${user.email}`);
console.log(` Role: ${user.role}`);
console.log(` Player: ${user.player.name}`);
console.log(` Created: ${user.createdAt}`);
console.log('');
});
console.log(`Total users: ${users.length}`);
} catch (error) {
console.error('Error listing users:', error);
} finally {
await prisma.$disconnect();
}
}
listUsers();
+27
View File
@@ -0,0 +1,27 @@
#!/bin/bash
# Start the dev server in background
echo "Starting dev server..."
npm run dev > /tmp/next-auth-test.log 2>&1 &
SERVER_PID=$!
# Wait for server to start
sleep 8
# Try to register via API
echo "Attempting to register admin user..."
curl -X POST http://localhost:3000/api/auth/sign-up/email \
-H "Content-Type: application/json" \
-d '{
"email": "david@dhg.lol",
"password": "admin",
"name": "David Admin"
}' \
2>/dev/null
echo ""
echo "Checking if user was created..."
sqlite3 prisma/dev.db "SELECT email, role FROM users;"
# Cleanup
kill $SERVER_PID 2>/dev/null
+51
View File
@@ -0,0 +1,51 @@
const { PrismaClient } = require('@prisma/client');
const bcrypt = require('bcryptjs');
const prisma = new PrismaClient();
async function main() {
try {
const newPassword = 'adminadmin';
// Find the admin user
const user = await prisma.user.findUnique({
where: { email: 'david@dhg.lol' }
});
if (!user) {
console.log('❌ Admin user not found');
return;
}
// Find the account
const account = await prisma.account.findFirst({
where: { userId: user.id }
});
if (!account) {
console.log('❌ Account not found for user');
return;
}
// Hash new password using bcrypt
const salt = await bcrypt.genSalt(12);
const passwordHash = await bcrypt.hash(newPassword, salt);
// Update the password
await prisma.account.update({
where: { id: account.id },
data: { password: passwordHash }
});
console.log('✅ Admin password updated successfully!');
console.log(' Email:', user.email);
console.log(' New Password:', newPassword);
} catch (error) {
console.error('❌ Error:', error.message);
} finally {
await prisma.$disconnect();
}
}
main();