-
Notifications
You must be signed in to change notification settings - Fork 44
Forgot Password Feature: Issue Fixed #58 #134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…bmission, verification, and password reset
- Added password reset service to handle token generation, validation, and password updates. - Created email utility for sending password reset emails with secure links. - Updated user model to include reset password fields (token and expiry). - Modified user controller and routes to include forgot and reset password endpoints. - Enhanced validation schemas for password reset requests. - Developed comprehensive setup guide and quick reference documentation. - Included security features such as token expiration and hashing. - Added testing commands and examples for API endpoints.
Thanks for creating a PR for your Issue!
|
Summary of ChangesHello @rdx-exe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request delivers a robust and secure password reset functionality for the backend. It integrates new database fields, API endpoints, and dedicated services to manage the entire password reset lifecycle, from token generation and email dispatch to password update and token invalidation. The implementation prioritizes security, user privacy, and ease of configuration, complemented by thorough documentation to facilitate understanding and future maintenance. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces a comprehensive and secure password reset feature, complete with backend logic, frontend components, and extensive documentation. The backend implementation is robust, following security best practices like using cryptographically secure tokens, hashing them for storage, setting expirations, and preventing email enumeration attacks. The separation of concerns into services and utilities is well-executed. However, there are several inconsistencies in the documentation that need to be addressed to avoid confusion. More critically, the new frontend component for handling the password reset flow is fundamentally mismatched with the backend's link-based implementation, as it's designed for a code-based verification flow. This will need to be redesigned to work correctly.
| const [step, setStep] = useState<'email' | 'verification' | 'reset'>('email') | ||
| const [verificationCode, setVerificationCode] = useState('') | ||
| const [newPassword, setNewPassword] = useState('') | ||
| const [confirmPassword, setConfirmPassword] = useState('') | ||
|
|
||
| const handleEmailSubmit = (e: React.FormEvent) => { | ||
| e.preventDefault() | ||
| // Handle email submission | ||
| console.log('Email submitted:', email) | ||
| setStep('verification') | ||
| } | ||
|
|
||
| const handleVerificationSubmit = (e: React.FormEvent) => { | ||
| e.preventDefault() | ||
| // Handle verification code | ||
| console.log('Verification code:', verificationCode) | ||
| setStep('reset') | ||
| } | ||
|
|
||
| const handleResetSubmit = (e: React.FormEvent) => { | ||
| e.preventDefault() | ||
| // Handle password reset | ||
| console.log('Password reset for:', email) | ||
| // Redirect to login after successful reset | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The UI flow implemented in this component is fundamentally mismatched with the backend's password reset logic. This component is designed for a multi-step process involving a 'verification code' (step state with 'email', 'verification', 'reset').
However, the backend implements a link-based flow:
- User submits their email.
- Backend sends an email with a unique URL like
.../reset-password/:token. - User clicks the link, which takes them to a new page to enter and confirm their new password.
There is no 'verification code' step. This component will not work with the backend as is. It needs to be redesigned to support the link-based flow. This likely involves:
- This component handling only the initial email submission.
- A new, separate component for the
/reset-password/:tokenroute that reads the token from the URL and presents the form to enter a new password.
| **Response (Error - 400):** | ||
| ```json | ||
| { | ||
| "success": false, | ||
| "message": "Invalid credentials" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation for the forgot-password endpoint's error response is misleading. It shows a 400 Bad Request with an error message. While this can happen for malformed input, a key security feature of this endpoint is that it always returns a success message for validly formatted requests (even if the email doesn't exist or an internal error occurs) to prevent email enumeration. The documentation should be updated to clarify this behavior, as it's a critical aspect of the API's security design.
| ┌──────────────────┐ ┌──────────────────────┐ | ||
| │ Forgot Password │ │ Reset Password │ | ||
| │ Page │ │ Page │ | ||
| │ /forgot-pwd │ │ /reset-password/:id │ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the System Architecture diagram, the route for the Reset Password Page is listed as /reset-password/:id. For consistency with the implementation and other documentation, this should be /reset-password/:token since the API uses a token, not a user ID, in the URL.
| │ /forgot-pwd │ │ /reset-password/:id │ | |
| │ /reset-password/:token│ |
| ├── user.service.ts # Business logic | ||
| ├── user.utils.ts # Helper functions | ||
| ├── user.validator.ts # Zod validation schemas | ||
| ├── user.constant.ts # Constants and config | ||
| ├── user.middleware.ts # Authentication middleware |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file structure diagram is inaccurate. It lists user.service.ts, user.utils.ts, and user.middleware.ts under the src/api/v1/user/ directory. However, the project structure places services in src/services/ and utilities in src/utils/. Please update the diagram to reflect the correct file locations to avoid confusion for developers.
| LocalMind-Backend/ | ||
| ├── src/ | ||
| │ ├── api/ | ||
| │ │ └── v1/ | ||
| │ │ └── user/ | ||
| │ │ ├── user.model.ts (✏️ MODIFIED - added reset fields) | ||
| │ │ ├── user.type.ts (✏️ MODIFIED - added interface) | ||
| │ │ ├── user.constant.ts (✏️ MODIFIED - added messages) | ||
| │ │ ├── user.controller.ts (✏️ MODIFIED - added methods) | ||
| │ │ ├── user.routes.ts (✏️ MODIFIED - added endpoints) | ||
| │ │ └── user.validator.ts (✏️ MODIFIED - added schemas) | ||
| │ ├── services/ | ||
| │ │ └── password-reset.service.ts (✨ NEW) | ||
| │ ├── utils/ | ||
| │ │ ├── email.utils.ts (✨ NEW) | ||
| │ │ └── SendResponse.utils.ts | ||
| │ ├── constant/ | ||
| │ │ └── env.constant.ts | ||
| │ ├── validator/ | ||
| │ │ └── env.ts (✏️ MODIFIED - added email vars) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file structure diagram in this guide is inconsistent with the actual project structure. It incorrectly places user.model.ts, user.type.ts, etc., inside the user directory, and also misplaces other files. Please update the diagram to accurately represent the file locations as implemented in the codebase to prevent confusion during setup and development.
- Added ResetPassword component for handling password reset with token validation. - Integrated API call to reset password and handle success/error states. - Enhanced ForgotPwd component to simplify flow and provide user feedback. - Integrated loading states and error/success messages in LoginPage and ForgotPwd. - Improved password validation in ResetPassword with real-time feedback. - Updated package.json dependencies for nodemailer and types.
Description
This pull request implements a production-ready, secure password reset feature across the backend authentication flow.
It introduces the necessary database changes, API endpoints, validation, services, configuration, and comprehensive documentation, with a strong focus on security, maintainability, and real-world deployment readiness.
Key Changes
🔐 Password Reset Implementation
resetPasswordTokenandresetPasswordExpirefields to theUsermodel and corresponding TypeScript interfaces, with secure defaults and exclusion from default queries.POST /api/v1/auth/forgot-passwordPOST /api/v1/auth/reset-password/:tokenpassword-reset.service.tsfor core reset logic andemail.utils.tsfor sending secure, HTML-formatted reset emails.🛡️ Security and Validation Enhancements
⚙️ Configuration and Documentation
IMPLEMENTATION_SUMMARY.mdPASSWORD_RESET_API.mdAUTHENTICATION_API.mdSETUP_GUIDE.md✅ Code Quality and Readiness
How to Test
SETUP_GUIDE.mdPOST /api/v1/auth/forgot-passwordwith a registered emailPOST /api/v1/auth/reset-password/:tokenRelated Issue
Closes #58