File size: 841 Bytes
71b8eb2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import bcrypt from 'bcryptjs';
import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

const ROUNDS = Number(process.env.BCRYPT_ROUNDS ?? 10);

const users = [
  { email: 'admin@polysignal.test', password: 'Admin123!' },
  { email: 'user@polysignal.test', password: 'User123!' },
];

const run = async () => {
  for (const u of users) {
    const passwordHash = await bcrypt.hash(u.password, ROUNDS);
    const record = await prisma.user.upsert({
      where: { email: u.email },
      update: { passwordHash, isActive: true },
      create: { email: u.email, passwordHash, isActive: true },
    });
    console.log(`seeded user ${record.email} (id=${record.id})`);
  }
};

run()
  .catch((err) => {
    console.error(err);
    process.exit(1);
  })
  .finally(async () => {
    await prisma.$disconnect();
  });