first commit
This commit is contained in:
49
prisma/seed.ts
Normal file
49
prisma/seed.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { PrismaClient, Role } from "@prisma/client";
|
||||
import * as argon2 from "argon2";
|
||||
import { randomBytes } from "node:crypto";
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const prisma = new PrismaClient({ datasourceUrl: process.env.DATABASE_URL });
|
||||
|
||||
const adminEmail = "admin@sso.local";
|
||||
const adminPassword = "admin123!";
|
||||
|
||||
const existingAdmin = await prisma.user.findUnique({ where: { email: adminEmail } });
|
||||
if (!existingAdmin) {
|
||||
const passwordHash = await argon2.hash(adminPassword);
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
email: adminEmail,
|
||||
passwordHash,
|
||||
displayName: "SSO Admin",
|
||||
role: Role.ADMIN,
|
||||
},
|
||||
});
|
||||
console.log(`Admin user created: ${adminEmail} / ${adminPassword}`);
|
||||
}
|
||||
|
||||
const testClientId = "test-client";
|
||||
const existingClient = await prisma.client.findUnique({ where: { clientId: testClientId } });
|
||||
if (!existingClient) {
|
||||
const clientSecret = randomBytes(32).toString("hex");
|
||||
await prisma.client.create({
|
||||
data: {
|
||||
name: "Test OAuth Client",
|
||||
clientId: testClientId,
|
||||
clientSecret,
|
||||
redirectUris: ["http://localhost:5173/callback", "http://localhost:3000/callback"],
|
||||
grants: ["authorization_code", "client_credentials", "refresh_token"],
|
||||
isConfidential: true,
|
||||
},
|
||||
});
|
||||
console.log(`OAuth client created: ${testClientId} / ${clientSecret}`);
|
||||
}
|
||||
|
||||
console.log("Seed complete.");
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error("Seed failed:", e);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user