Skip to content

Signup Login Functionality Added#151

Open
ChandraST12 wants to merge 7 commits into
SwanandD121:mainfrom
ChandraST12:main
Open

Signup Login Functionality Added#151
ChandraST12 wants to merge 7 commits into
SwanandD121:mainfrom
ChandraST12:main

Conversation

@ChandraST12

@ChandraST12 ChandraST12 commented Oct 14, 2024

Copy link
Copy Markdown
Contributor

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.)

@vercel

vercel Bot commented Oct 14, 2024

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
feather-perfect-fe ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 23, 2024 3:47pm

@ChandraST12

Copy link
Copy Markdown
Contributor Author

I have provided the .env.sample file

PORT = 4000
MONGODB_URL="YOUR_MONGODB_URL"

MAIL_HOST=smtp.gmail.com
MAIL_USER=
MAIL_PASS=

JWT_SECRET ="JWT_SECRET_HERE"


To configure **Gmail SMTP** in your **.env** file, please follow these steps:

1. **Enable App Passwords** (Recommended):
   - Go to [Google Security](https://myaccount.google.com/security).
   - Enable **2-Step Verification** for your Google account.
   - Under **App passwords**, create a password for "Mail".
   - Copy the generated 16-character password; this will be used as your `MAIL_PASS`.

2. Update your `.env` file with the following values:
   ```plaintext
   MAIL_HOST=smtp.gmail.com
   MAIL_USER=your-email@gmail.com
   MAIL_PASS=your-16-character-app-password



@ChandraST12

Copy link
Copy Markdown
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.

@SwanandD121 SwanandD121 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will review it

@samyakmaitre samyakmaitre left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Reviewed

@ChandraST12

Copy link
Copy Markdown
Contributor Author

@SwanandD121 when will you merge this PR

@ChandraST12

Copy link
Copy Markdown
Contributor Author

please merge the PR otherwise it will be not considered as contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants