43 lines
1.0 KiB
JavaScript
43 lines
1.0 KiB
JavaScript
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@bizone.id';
|
|
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();
|
|
});
|