feat: implement secure admin authentication system with JWT sessions, middleware protection, and Prisma schema initialization

This commit is contained in:
Yolando
2026-03-28 20:38:47 +07:00
parent 53da46def1
commit 0549f12a97
13 changed files with 1100 additions and 6 deletions

34
prisma/seed.ts Normal file
View 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();
});