fix: update admin scripts to use PostgreSQL adapter and dotenv
This commit is contained in:
@@ -1,22 +1,42 @@
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
const { betterAuth } = require('better-auth');
|
||||
const { prismaAdapter } = require('better-auth/adapters/prisma');
|
||||
const { PrismaPg } = require('@prisma/adapter-pg');
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
// Load environment variables from .env file
|
||||
require('dotenv').config();
|
||||
|
||||
// Check if DATABASE_URL is set
|
||||
if (!process.env.DATABASE_URL) {
|
||||
console.error('❌ DATABASE_URL environment variable is not set');
|
||||
console.error(' Please set DATABASE_URL in your environment or .env file');
|
||||
console.error(' Example: DATABASE_URL="postgresql://user:password@localhost:5432/dbname"');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Create PrismaClient with adapter (matching src/lib/prisma.ts)
|
||||
const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL });
|
||||
const prisma = new PrismaClient({ adapter });
|
||||
|
||||
// Create Better Auth instance
|
||||
const auth = betterAuth({
|
||||
database: prismaAdapter(prisma, {
|
||||
provider: 'sqlite',
|
||||
provider: 'postgresql',
|
||||
}),
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
},
|
||||
baseURL: process.env.BETTER_AUTH_URL || 'http://localhost:3000',
|
||||
secret: process.env.BETTER_AUTH_SECRET || process.env.NEXTAUTH_SECRET || 'your-secret-key-here-change-this-in-production',
|
||||
});
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
// Test database connection first
|
||||
console.log('Connecting to database...');
|
||||
await prisma.$connect();
|
||||
console.log('✅ Connected to database');
|
||||
|
||||
// Check if user exists
|
||||
const existing = await prisma.user.findUnique({
|
||||
where: { email: 'david@dhg.lol' }
|
||||
|
||||
Reference in New Issue
Block a user