Implement authentication using Passport.js

This commit is contained in:
Aaron William Po
2023-02-05 19:27:19 -05:00
parent 86f6f9abc5
commit 087a1a4513
26 changed files with 2073 additions and 412 deletions

View File

@@ -1,3 +1,4 @@
import argon2 from 'argon2';
// eslint-disable-next-line import/no-extraneous-dependencies
import { faker } from '@faker-js/faker';
import DBClient from '../../DBClient';
@@ -9,12 +10,19 @@ interface CreateNewUsersArgs {
const createNewUsers = async ({ numberOfUsers }: CreateNewUsersArgs) => {
const prisma = DBClient.instance;
const userPromises = [];
const hashedPasswords = await Promise.all(
Array.from({ length: numberOfUsers }, () => argon2.hash(faker.internet.password())),
);
// eslint-disable-next-line no-plusplus
for (let i = 0; i < numberOfUsers; i++) {
const firstName = faker.name.firstName();
const lastName = faker.name.lastName();
const username = `${firstName[0]}.${lastName}`;
const email = faker.internet.email(firstName, lastName, 'example.com');
const username = `${firstName[0]}.${lastName}.${i}`;
const email = faker.internet.email(firstName, lastName + i, 'example.com');
const hash = hashedPasswords[i];
const dateOfBirth = faker.date.birthdate({ mode: 'age', min: 19 });
const createdAt = faker.date.past(1);
userPromises.push(
@@ -26,6 +34,7 @@ const createNewUsers = async ({ numberOfUsers }: CreateNewUsersArgs) => {
username,
dateOfBirth,
createdAt,
hash,
},
}),
);