Initial BizOne portal setup
This commit is contained in:
42
backend/prisma/seed-admin.js
Normal file
42
backend/prisma/seed-admin.js
Normal file
@ -0,0 +1,42 @@
|
||||
const path = require('node:path');
|
||||
const { PrismaClient } = require('@prisma/client');
|
||||
const bcrypt = require('bcryptjs');
|
||||
const dotenv = require('dotenv');
|
||||
|
||||
dotenv.config({ path: path.resolve(process.cwd(), '../.env'), quiet: true });
|
||||
dotenv.config({ path: path.resolve(process.cwd(), '.env'), quiet: true });
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
const email = 'admin@example.com';
|
||||
const password = 'ChangeMe123!';
|
||||
const passwordHash = await bcrypt.hash(password, 10);
|
||||
|
||||
const user = await prisma.user.upsert({
|
||||
where: { email },
|
||||
update: {
|
||||
name: 'System Admin',
|
||||
passwordHash,
|
||||
status: 'active',
|
||||
},
|
||||
create: {
|
||||
name: 'System Admin',
|
||||
email,
|
||||
passwordHash,
|
||||
status: 'active',
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Seeded admin user: ${user.email}`);
|
||||
console.log(`Recommended credentials: ${email} / ${password}`);
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user