This project is aimed at developing a secure user registration and authentication system using Express.js and MongoDB. It includes APIs for user registration, email verification, user information update, user login, and retrieval of user information using JWT token authentication.
- Express.js
- MongoDB
- JSON Web Tokens (JWT)
- Node.js
- Clone the repository from GitHub.
- Navigate to the project directory.
- Install dependencies using
npm install
. - Start the local server using
npm run server
.
- URL:
/api/register
- Method: POST
- Request Body:
- email (string): User's email address
- password (string): User's password
- Response:
- Success: Status 200 OK
- Error: Status 400 Bad Request
- URL:
/api/generateOTP
- Method: POST
- Request Body:
- email (string): User's email address
- password (string): User's password
- Response:
- Success: Status 200 OK
- Error: Status 400 Bad Request
- URL:
/api/verifyOTP
- Method: POST
- Request Body:
- email (string): User's email address
- otp (string): One-time password sent to the user's email
- Response:
- Success: Status 200 OK
- Error: Status 400 Bad Request
- URL:
/api/updateUser
- Method: PUT
- Request Body:
- email (string): User's email address
- location (string)
- age (string)
- work_Details (string)
- Response:
- Success: Status 200 OK
- Error: Status 400 Bad Request
- URL:
/api/login
- Method: POST
- Request Body:
- email (string): User's email address
- password (string): User's password
- Response:
- Success: JWT token with Status 200 OK
- Error: Status 401 Unauthorized
- URL:
/api/userinfo
- Method: GET
- Request Header:
- Authorization: Bearer
- Response:
- Success: User information with Status 200 OK
- Error: Status 401 Unauthorized
Attached screenshots of each API from POSTMAN.
const UserSchema = new Schema({
email: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true
},
isVerified: {
type: Boolean,
default: false
},
location: {
type: String
},
age: {
type: Number
},
work_details: {
type: String
}
});