Fix bcryptjs imports to use dynamic imports

This commit is contained in:
Randall Stillwell 2025-07-23 09:40:50 -05:00
parent 20c2439ff4
commit 373f103810
2 changed files with 8 additions and 3 deletions

View file

@ -1,14 +1,15 @@
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
import bcrypt from 'bcryptjs';
import { sql } from '@vercel/postgres'; import { sql } from '@vercel/postgres';
const JWT_SECRET = process.env.JWT_SECRET || 'your-secret-key'; const JWT_SECRET = process.env.JWT_SECRET || 'your-secret-key';
export async function hashPassword(password) { export async function hashPassword(password) {
const bcrypt = await import('bcryptjs');
return await bcrypt.hash(password, 12); return await bcrypt.hash(password, 12);
} }
export async function verifyPassword(password, hashedPassword) { export async function verifyPassword(password, hashedPassword) {
const bcrypt = await import('bcryptjs');
return await bcrypt.compare(password, hashedPassword); return await bcrypt.compare(password, hashedPassword);
} }

View file

@ -125,7 +125,7 @@ export default async function handler(req, res) {
`; `;
// Create a default admin user // Create a default admin user
const bcrypt = require('bcryptjs'); const bcrypt = await import('bcryptjs');
const hashedPassword = await bcrypt.hash('admin123', 12); const hashedPassword = await bcrypt.hash('admin123', 12);
await sql` await sql`
@ -137,7 +137,11 @@ export default async function handler(req, res) {
res.status(200).json({ res.status(200).json({
success: true, success: true,
message: 'Database setup completed successfully!', message: 'Database setup completed successfully!',
tables: ['users', 'cards', 'user_cards', 'collections', 'collection_cards', 'decks', 'deck_cards'] tables: ['users', 'cards', 'user_cards', 'collections', 'collection_cards', 'decks', 'deck_cards'],
adminUser: {
email: 'admin@tcgvault.com',
password: 'admin123'
}
}); });
} catch (error) { } catch (error) {