MaternAlert / src /create-super-admin.ts
Auspicious14's picture
feat: add patient update API and improve admin scripts
5f952c4
Raw
History Blame Contribute Delete
1.35 kB
import { PrismaClient } from "@prisma/client";
import { PrismaPg } from "@prisma/adapter-pg";
import { Pool } from "pg";
import * as bcrypt from "bcrypt";
import * as dotenv from "dotenv";
// Load environment variables
dotenv.config();
// Initialize Prisma Client with adapter
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
ssl: {
rejectUnauthorized: false,
},
});
const prisma = new PrismaClient({
adapter: new PrismaPg(pool),
});
async function main() {
const email = "admin@maternalert.com";
const password = "123456";
// Check if user already exists
const existingUser = await prisma.userAuth.findUnique({
where: { email },
});
if (existingUser) {
console.log("Super admin already exists!");
return;
}
// Hash password
const passwordHash = await bcrypt.hash(password, 10);
// Create super admin
const user = await prisma.userAuth.create({
data: {
email,
passwordHash,
role: "SUPER_ADMIN",
isActive: true,
status: "ACTIVE",
},
});
console.log("Super admin created successfully!");
console.log("Email:", email);
console.log("Password:", password);
console.log("User ID:", user.id);
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});