/** * Seed script — creates the first admin user. * Run: npm run db:seed * * It reads ADMIN_EMAIL and ADMIN_PASSWORD from environment variables, * or falls back to admin@example.com / changeme. * * Usage in Replit Secrets: * ADMIN_EMAIL=you@yourdomain.com * ADMIN_PASSWORD=your-secure-password */ import "dotenv/config"; import bcrypt from "bcrypt"; import { db } from "../server/db"; import { adminUsers } from "../shared/schema"; import { eq } from "drizzle-orm"; const email = process.env.ADMIN_EMAIL || "admin@example.com"; const password = process.env.ADMIN_PASSWORD || "changeme"; async function seed() { const existing = await db.select().from(adminUsers).where(eq(adminUsers.email, email)); if (existing.length) { console.log(`Admin ${email} already exists.`); process.exit(0); } const passwordHash = await bcrypt.hash(password, 12); await db.insert(adminUsers).values({ email, passwordHash, role: "superadmin" }); console.log(`✓ Admin created: ${email}`); process.exit(0); } seed().catch((err) => { console.error(err); process.exit(1); });