1. User Registration
- User Input Collection:
- React: Form collects email and password.
- Validation:
- Client-side (React): Validates email format and password strength.
- Server-side (Express.js): Uses
express-validator to enforce rules and prevent invalid data.
- Check for Existing Users:
- MongoDB (Mongoose): Checks if the email already exists.
- Password Hashing:
- bcrypt: Hashes the password to ensure secure storage.
- Save User:
- Mongoose: Saves user details in MongoDB.
- Response to Client:
- Express.js: Sends success or error message back to React.
2. User Login
- User Input Collection:
- React: Form collects email and password.
- Validation:
- Client-side (React): Ensures fields are filled correctly.
- Server-side (Express.js): Validates credentials.
- User Lookup:
- MongoDB (Mongoose): Finds user by email.
- Password Verification:
- bcrypt: Compares entered password with hashed password.
- Token Generation:
- jsonwebtoken: Generates a JWT containing user information.
- Send Token to Client:
- Express.js: Returns JWT to React for session management.
3. Forgot Password
- Request Password Reset:
- React: Form for entering the email.
- Validation:
- Express.js: Checks if the email exists in MongoDB.
- Generate Reset Token:
- crypto: Creates a secure token.
- Store Token:
- Mongoose: Stores token and expiry time in MongoDB.