34 lines
788 B
TypeScript
34 lines
788 B
TypeScript
import { PrismaClient } from './prisma/client.js';
|
|
import bcrypt from 'bcrypt';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
const email = 'owner@travel.com';
|
|
const newPassword = 'admin123';
|
|
const hash = await bcrypt.hash(newPassword, 10);
|
|
|
|
const user = await prisma.user.findUnique({ where: { email } });
|
|
if (!user) {
|
|
console.log('Tạo tài khoản admin mới...');
|
|
await prisma.user.create({
|
|
data: {
|
|
email,
|
|
passwordHash: hash,
|
|
name: 'Admin',
|
|
isAdmin: true,
|
|
},
|
|
});
|
|
} else {
|
|
await prisma.user.update({
|
|
where: { email },
|
|
data: { passwordHash: hash, isAdmin: true },
|
|
});
|
|
}
|
|
|
|
console.log(`Đã cập nhật xong mật khẩu cho ${email}`);
|
|
await prisma.$disconnect();
|
|
}
|
|
|
|
main();
|