Initial import: property management SaaS + security hardening + admin dashboard
Property Management Network — Next.js 16 (App Router), Better Auth, Drizzle ORM over PostgreSQL, Stripe, OpenAI, Resend. Includes: - Security hardening: access-control/IDOR fixes, TLS-by-default DB layer, constant-time cron auth, strict security headers, atomic AI quota gating, HTML/email output encoding, demo-backdoor disabled in production. - Superadmin dashboard at /admin (overview/MRR, server-paginated users with ban/impersonate/plan/delete, billing, platform activity + admin audit log, AI usage, system health) via the Better Auth admin plugin. - Seed/migration utility scripts under scripts/. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
/**
|
||||
* Create (or reset) the platform superadmin: admin@demo.test / Admin123!
|
||||
* Sets user.role = 'admin' so both our requireAdmin() gate and the Better Auth
|
||||
* admin plugin authorize it. Password is hashed (Better Auth node scrypt).
|
||||
*
|
||||
* Run: npx tsx scripts/seed-admin.ts
|
||||
*/
|
||||
import { config } from "dotenv"
|
||||
config({ path: ".env.local" })
|
||||
process.env.DATABASE_SSL = process.env.DATABASE_SSL ?? "disable"
|
||||
|
||||
import { randomUUID } from "node:crypto"
|
||||
|
||||
const EMAIL = "admin@demo.test"
|
||||
const PASSWORD = "Admin123!"
|
||||
|
||||
async function main() {
|
||||
const { db, pool } = await import("../lib/db")
|
||||
const s = await import("../lib/db/schema")
|
||||
const { eq } = await import("drizzle-orm")
|
||||
const { hashPassword } = await import("better-auth/crypto")
|
||||
|
||||
await db.delete(s.user).where(eq(s.user.email, EMAIL))
|
||||
|
||||
const userId = randomUUID()
|
||||
const now = new Date()
|
||||
await db.insert(s.user).values({
|
||||
id: userId,
|
||||
name: "Platform Admin",
|
||||
email: EMAIL,
|
||||
emailVerified: true,
|
||||
role: "admin",
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
})
|
||||
await db.insert(s.account).values({
|
||||
id: randomUUID(),
|
||||
accountId: userId,
|
||||
providerId: "credential",
|
||||
userId,
|
||||
password: await hashPassword(PASSWORD),
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
})
|
||||
await db.insert(s.profiles).values({
|
||||
id: userId,
|
||||
email: EMAIL,
|
||||
full_name: "Platform Admin",
|
||||
plan: "lifetime",
|
||||
onboarding_completed: true,
|
||||
})
|
||||
|
||||
console.log(`✓ Superadmin ready`)
|
||||
console.log(` email: ${EMAIL}`)
|
||||
console.log(` password: ${PASSWORD}`)
|
||||
console.log(` user id: ${userId}`)
|
||||
console.log(` role: admin`)
|
||||
await pool.end()
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error("seed-admin failed:", e)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user