Signup Login Functionality Added#151
Open
ChandraST12 wants to merge 7 commits into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Contributor
Author
|
I have provided the .env.sample file PORT = 4000 MAIL_HOST=smtp.gmail.com JWT_SECRET ="JWT_SECRET_HERE" |
Contributor
Author
|
I have added comments for better understanding of each and every step of the approach. They can be removed after completing the backend functionalities. |
Contributor
Author
|
@SwanandD121 when will you merge this PR |
Contributor
Author
|
please merge the PR otherwise it will be not considered as contributor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
issue #43
Project Structure:
Create a server folder: This folder will contain all the backend-related files for your application, including models, controllers, routes, middleware, and utility files.
Models:
User Model: This will handle user-related information such as firstName, lastName, email, password.
OTP Model: This will store OTPs generated for user registration or password reset purposes, with fields for the email and otp.
Additionally added Profile model for further improvement in backend and frontend.
Middleware:
Authorization Middleware: To protect certain routes and ensure that users are authenticated, implement JWT (JSON Web Token) authentication. This middleware will check the validity of the JWT token for protected routes like changePassword.
Controllers: The business logic of the application will be placed in controllers. These functions will be responsible for:
Sign Up:
Validate input fields.
Check if the user already exists.
Verify the OTP sent to the user.
Hash the password using bcrypt and create a new user.
Login:
Authenticate the user by verifying the email and password.
Generate and return a JWT token for future authentication.
Change Password:
Validate the old password and ensure the new password matches the confirmation password.
Hash and update the new password in the database.
Send OTP:
Generate a unique OTP using the otp-generator library.
Ensure the OTP is unique and store it in the OTP model.
Respond with the generated OTP or send it via email.
Routes: Routes will define the endpoints for interacting with the backend and map to the appropriate controller functions:
POST /auth/signup: For user registration.
POST /auth/login: For logging in users.
POST /auth/sendOtp: To generate and send OTP for registration or password recovery.
PUT /auth/change-password: For users to change their password (JWT protected).
Folder Structure
/server
├── controllers
│ ├── authController.js # Handles login, signup, change password
│ ├── otpController.js # Handles OTP generation and validation
├── models
│ ├── User.js # User model schema
│ ├── OTP.js # OTP model schema
│
├── middleware
│ └── auth.js # JWT authorization middleware
├── routes
│ ├── authRoutes.js # Authentication-related routes
├── utils
│ └── mailSender.js # Utility for sending emails
├── index.js # Main server file
└── .env # Environment variables (JWT secret, etc.)