File size: 1,347 Bytes
c35b446
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d84b47
c35b446
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5f952c4
c35b446
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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();
  });