creating the first user, where disableSignUp is true
Hi, are there any suggestions on how to do this? I've created the DB schema fine but with this off and no API in place yet I was hoping there'd be a CLI command
"bun run server/src/db/seed.ts"import { db } from "./index";
import { user, account } from "./auth-schema";
import { eq } from "drizzle-orm";
import { hashPassword } from "better-auth/crypto";
// Seed the database with admin user
async function main() {
const adminEmail = process.env.ADMIN_EMAIL || "admin@example.com";
const adminUser = await db.select().from(user).where(eq(user.email, adminEmail));
if (adminUser.length > 0) {
console.log("Admin user already exists");
return;
}
console.log("Seeding the database with the initial data");
try {
const adminUser = {
"id": "app-admin",
"name": "Admin",
"email": adminEmail,
"emailVerified": true,
"role": "admin",
"createdAt": new Date(),
"updatedAt": new Date(),
}
const adminAccount = {
"id": "app-admin-main-account",
"accountId": "app-admin",
"providerId": "credential",
"userId": "app-admin",
"accessToken": null,
"refreshToken": null,
"idToken": null,
"accessTokenExpiresAt": null,
"refreshTokenExpiresAt": null,
"scope": null,
"password": await hashPassword(process.env.ADMIN_PASSWORD || "password123"),
"createdAt": new Date(),
"updatedAt": new Date()
}
await db.insert(user).values(adminUser);
await db.insert(account).values(adminAccount);
console.log("Admin user created successfully");
} catch (error) {
console.error("Error creating admin user:", error);
}
}
main();