From ed83cdf185a1a10c808c0f66d617499851c412f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Tonh=C3=A4user?= Date: Mon, 10 Aug 2026 22:44:32 +0200 Subject: [PATCH] feat: add admin seed script --- scripts/create-admin.ts | 44 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 scripts/create-admin.ts diff --git a/scripts/create-admin.ts b/scripts/create-admin.ts new file mode 100644 index 0000000..03616bd --- /dev/null +++ b/scripts/create-admin.ts @@ -0,0 +1,44 @@ +import { eq } from "drizzle-orm"; +import { auth } from "../src/modules/auth/auth"; +import { db } from "../src/db/client"; +import { users } from "../src/db/schema"; + +async function main() { + const email = process.argv[2] || "mail@leon-tonhaeuser.de"; + const password = process.argv[3] || "AdminPassword123!"; + const name = process.argv[4] || "Leon Tonhäuser"; + + console.log(`Creating Admin user: ${email}...`); + + try { + const res = await auth.api.signUpEmail({ + body: { + email, + name, + password, + }, + }); + + const userId = res.user.id; + await db.update(users).set({ role: "ADMIN", emailVerified: true }).where(eq(users.id, userId)); + + console.log(`Successfully created Admin account!`); + console.log(`Email: ${email}`); + console.log(`Password: ${password}`); + } catch (error) { + console.error("Error creating admin user:", error); + // If user already exists, update to admin + const [existing] = await db.select().from(users).where(eq(users.email, email)); + if (existing) { + await db.update(users).set({ role: "ADMIN", emailVerified: true }).where(eq(users.id, existing.id)); + console.log(`Updated existing user ${email} to ADMIN role.`); + } + } + + process.exit(0); +} + +main().catch((err) => { + console.error("Fatal error:", err); + process.exit(1); +});