feat: implement secure admin authentication system with JWT sessions, middleware protection, and Prisma schema initialization
This commit is contained in:
34
prisma/seed.ts
Normal file
34
prisma/seed.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
import { hash } from "bcryptjs";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
async function main() {
|
||||
console.log("Seeding database...");
|
||||
|
||||
const adminEmail = process.env.ADMIN_EMAIL || "admin@ando.dev";
|
||||
const rawPassword = process.env.ADMIN_PASSWORD || "admin123";
|
||||
const passwordHash = await hash(rawPassword, 12);
|
||||
|
||||
// Upsert ensures we don't insert duplicate admins if the seeder runs twice
|
||||
const user = await prisma.user.upsert({
|
||||
where: { email: adminEmail },
|
||||
update: {},
|
||||
create: {
|
||||
email: adminEmail,
|
||||
name: "Yolando Admin",
|
||||
passwordHash,
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Admin user created: ${user.email}`);
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect();
|
||||
});
|
||||
Reference in New Issue
Block a user