Skip to content

Commit

Permalink
fix saving of password
Browse files Browse the repository at this point in the history
  • Loading branch information
mariovyord committed Jan 8, 2024
1 parent 48925b1 commit b867fbe
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
4 changes: 0 additions & 4 deletions src/features/user/user-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@ export class User {
public async comparePassword(password: string) {
return bcrypt.compare(password, this.password);
}

public async setPassword(password: string) {
this.password = await bcrypt.hash(password, 10);
}
}
6 changes: 3 additions & 3 deletions src/features/user/user-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IUserLocal, ISignUpUserData, UserDto, IUpdateUserData } from "./user-ty
import { BadRequestError, InternalServerError, NotFoundError, UnauthorizedError } from "../../utils/app-error";
import { User } from "./user-entity";
import { getUserRepository } from "./user-repository";
import bcrypt from "bcrypt";

export async function signUp(userData: ISignUpUserData): Promise<[string, UserDto]> {
if (!userData.username) {
Expand All @@ -22,7 +23,7 @@ export async function signUp(userData: ISignUpUserData): Promise<[string, UserDt
user.username = userData.username;
user.first_name = userData.firstName;
user.last_name = userData.lastName;
user.setPassword(userData.password);
user.password = await bcrypt.hash(userData.password, 10);
user.created_at = new Date();
user.updated_at = new Date();

Expand Down Expand Up @@ -113,8 +114,7 @@ export async function updatePassword(userId: string, oldPassword: string, newPas
throw new UnauthorizedError();
}

user.setPassword(newPassword);

user.password = await bcrypt.hash(newPassword, 10);
user.updated_at = new Date();

await getUserRepository().save(user);
Expand Down

0 comments on commit b867fbe

Please sign in to comment.