Skip to content

Commit

Permalink
feat: add a security measure to forgot-password
Browse files Browse the repository at this point in the history
  • Loading branch information
HJassar committed Oct 17, 2022
1 parent 7826104 commit dad0e99
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/modules/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const refreshTokens = catchAsync(async (req: Request, res: Response) => {
export const forgotPassword = catchAsync(async (req: Request, res: Response) => {
const resetPasswordToken = await tokenService.generateResetPasswordToken(req.body.email);
await emailService.sendResetPasswordEmail(req.body.email, resetPasswordToken);
res.status(httpStatus.NO_CONTENT).send();
res.status(httpStatus.NO_CONTENT).send('');
});

export const resetPassword = catchAsync(async (req: Request, res: Response) => {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/token/token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const generateAuthTokens = async (user: IUserDoc): Promise<AccessAndRefre
export const generateResetPasswordToken = async (email: string): Promise<string> => {
const user = await userService.getUserByEmail(email);
if (!user) {
throw new ApiError(httpStatus.NOT_FOUND, 'No users found with this email');
throw new ApiError(httpStatus.NO_CONTENT, '');
}
const expires = moment().add(config.jwt.resetPasswordExpirationMinutes, 'minutes');
const resetPasswordToken = generateToken(user.id, expires, tokenTypes.RESET_PASSWORD);
Expand Down

0 comments on commit dad0e99

Please sign in to comment.