Implement Secure Password Reset Flow #39
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implement Secure Password Reset Flow
This PR implements the forgot password and reset password functionality with email verification using a resendable token.
Changes Made
Accepts user email from the request.
Generates a JWT reset token valid for 1 hour.
Saves the token in the user’s refreshToken field.
Sends an email to the user with a password reset link.
Returns a success message if the email is sent, or an error if the user is not found.
Accepts reset token from URL params and new password from request body.
Verifies the token and checks if it matches the stored refreshToken.
Updates the user’s password and clears the refreshToken.
Returns a success message on successful reset, or an error for invalid/expired tokens.
Testing Instructions
Make a POST request to /api/auth/forgotPassword with the user email.
Check the email for the reset link.
Make a POST request to /api/auth/resetPassword/:token with the new password.
Confirm that the password is updated and the token cannot be reused.