Skip to content

Commit c114cdf

Browse files
authored
Merge pull request #18 from NextStepFinalProject/NXD-20
Hotfix Patch User Password Encryption
2 parents cee595b + 0204e45 commit c114cdf

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

nextstep-backend/src/services/users_service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export const getUserById = async (id: string): Promise<UserData | null> => {
4040

4141

4242
export const updateUserById = async (id: string, updateData: Partial<UserData>): Promise<UserData | null> => {
43+
if (updateData.password) {
44+
const salt = config.token.salt();
45+
updateData.password = await bcrypt.hash(updateData.password, salt);
46+
}
4347
const user = await UserModel.findByIdAndUpdate(id, updateData, { new: true }).exec();
4448
return user ? userToUserData(user) : null;
4549
};

0 commit comments

Comments
 (0)