This is a CRUD (Create, Read, Update, Delete) API for user authentication and email verification, built using Express.js and MongoDB. The API provides endpoints to manage user accounts, including #, login, email verification, JWT authentication and basic user profile operations.
- User #: Allows new users to create an account by providing a full name, unique email and password.
- verification mail is sent to user after #
- User login: Authenticates users for subsequent requests.
- JWT token is sent after user login.
- On every request user must send token in header with key as "token".
- Update user profile: Enables users to update their profile information, such as name, email, mobile number, or password.
- Delete user account: Allows users to delete their account and associated data from the database.
- Email Authentication: Sends one time email verification link on #.
- Use an API testing tool ( Postman ) to interact with the API endpoints.
- Email verification html files are served by api.
The following API endpoints are available:
- GET /profile/userdata : Featches user details from token provided.
- POST /profile/# : Creates a new user account and sends verification link to provided email.
- POST /profile/# : Authenticates the user and provides JWT token.
- PATCH /profile/update : Updates the profile information for the user and returns updated token.
- DELETE /profile/delete : Deletes the account for the user.
- GET /verify/:id : Verification Link in email.
{
"token": "jwt-token"
}
- Request
- Response
{
"fullname": "user full name",
"email": "user@gmail.com",
"password": "user password"
}
{
"status": 200,
"content": "Email verification link sent"
}
- Request
- Response
{
"email": "user@gmail.com",
"password": "user password"
}
{
"status": 200,
"token": "jwt-token"
}
- Response
{
"status": 200,
"data": {
// necessary data
}
}
- Request
- Response
( "data" object may contain any information of username, email or password. )
{
"data": {
"fullname": "new-username",
"email": "new-email",
"password": "new-password"
}
}
{
"status": 200,
"content": "User updated",
"token": "new-updated-jwt-token"
}
- Response
{
"status": 200,
"content": "User deleted"
}
The following environment variables need to be set for the project to function correctly:
- `MONGO_URL`: Url of mongoDB database, where data is to be stored.
- `USERAUTH`: Admin email for nodemailer authentication. Example: `admin@gmail.com`.
- `PASAUTH`: Application passord of email generated by google. Example: `xxxx xxxx xxxx`.
- `URL`: IP or DNS name of the server hosted. Example: `http://localhost:8080`.
- `JWTKEY`: JWT key to create and encrypt json web token.
We value and appreciate contributions from the community, whether it's fixing a bug, adding a new feature, improving documentation, or suggesting enhancements.