Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"bcryptjs": "^2.4.3",
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"email-validator": "^2.0.4",
"express": "~4.18.1",
"express-jwt": "^8.4.1",
"jsonwebtoken": "^9.0.2",
Expand Down
15 changes: 14 additions & 1 deletion src/app/routes/auth/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as bcrypt from 'bcryptjs';
import { validate } from 'email-validator';
import { RegisterInput } from './register-input.model';
import prisma from '../../../prisma/prisma-client';
import HttpException from '../../models/http-exception.model';
Expand Down Expand Up @@ -53,6 +54,10 @@ export const createUser = async (input: RegisterInput): Promise<RegisteredUser>
throw new HttpException(422, { errors: { password: ["can't be blank"] } });
}

if (!validate(email)) {
throw new HttpException(422, { errors: { email: ["is invalid"] } });
}

await checkUserUniqueness(email, username);

const hashedPassword = await bcrypt.hash(password, 10);
Expand Down Expand Up @@ -93,6 +98,10 @@ export const login = async (userPayload: any) => {
throw new HttpException(422, { errors: { password: ["can't be blank"] } });
}

if (!validate(email)) {
throw new HttpException(422, { errors: { email: ["is invalid"] } });
}

const user = await prisma.user.findUnique({
where: {
email,
Expand Down Expand Up @@ -150,8 +159,12 @@ export const getCurrentUser = async (id: number) => {

export const updateUser = async (userPayload: any, id: number) => {
const { email, username, password, image, bio } = userPayload;
let hashedPassword;

if (email && !validate(email)) {
throw new HttpException(422, { errors: { email: ["is invalid"] } });
}

let hashedPassword;
if (password) {
hashedPassword = await bcrypt.hash(password, 10);
}
Expand Down