feat: add admin authentication

This commit is contained in:
2026-09-18 16:50:35 +08:00
parent b89853bc94
commit bb5ccb1359
9 changed files with 85 additions and 1 deletions

View File

@@ -138,6 +138,18 @@ model Tag {
@@unique([brandId, name])
}
model AdminUser {
id String @id @default(uuid())
username String @unique
passwordHash String
displayName String
role String @default("admin")
isEnabled Boolean @default(true)
lastLoginAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
model BookingTag {
bookingId String
tagId String

View File

@@ -1,4 +1,5 @@
import { PrismaClient } from "@prisma/client";
import { hash } from "bcryptjs";
const prisma = new PrismaClient();
@@ -54,6 +55,15 @@ async function main(): Promise<void> {
create: { brandId: brand.id, name, isPreset: true },
});
}
await prisma.adminUser.upsert({
where: { username: "admin" },
update: {},
create: {
username: "admin",
passwordHash: await hash(process.env.SEED_ADMIN_PASSWORD ?? "change-me-now-123", 12),
displayName: "品牌管理员",
},
});
}
main().finally(() => prisma.$disconnect());