This Node.js project is designed to handle user signups and send verification emails using Nodemailer. Upon successful signup through the endpoint http://localhost:3000/auth/signup
, a verification email containing a URL is sent to the user. The user can click on the URL to verify their account.
- User signup endpoint (
/auth/signup
) for account creation. - Nodemailer integration to send verification emails.
- Token-based email verification for enhanced security.
Make sure you have the following installed before running the project:
-
Node.js
-
npm (Node Package Manager)
Create a
.env
file with belowPORT=<server port> MONGODB_URI=<mangodb cluster URL> JWT_SECRET=<any random secret key> EMAIL_SENDER=<sendermail> EMAIL_APPPASS=<Mail APP Passcode>
-
Clone the repository:
git clone https://github.com/yourusername/node-email-verification.git
Copy paste the
.env
file created above in this project -
Setup Project
npm install
-
Start server
node app.js
This API endpoint is responsible for user registration and account creation. Users can sign up by sending a POST request to http://localhost:3000/auth/signup
with the required information in the request body.
- Method: POST
- Endpoint:
/auth/signup
- fullname (string): The full name of the user.
- username (string): The email address or username for the user's account.
- password (string): The chosen password for the user's account.
- confirmPassword (string): Confirmation of the chosen password.
{
"fullname": "String",
"username": "String",
"password": "String",
"confirmPassword": "String"
}
This API endpoint handles user authentication. Users can sign in by sending a POST request to http://localhost:3000/auth/signin
with their username and password in the request body.
- Method: POST
- Endpoint:
/auth/signin
- username (string): The email address or username associated with the user's account.
- password (string): The user's password.
{
"username": "string",
"password": "string"
}
This API endpoint allows fetching user information based on the provided username. Authentication is required through either a Bearer token or Basic Authentication.
Bearer token will be generated in response once you access the Signin.
- Method: GET
- Endpoint:
/users/{username}
Access to this endpoint requires authentication. You can provide authentication using either of the following methods:
Include a valid Bearer token in the Authorization header:
Authorization: Bearer your_access_token
If you are using postman, go to Authorization and select the Bearer token in type.
This API endpoint allows updating user information based on the provided username. Authentication is required through either a Bearer token or Basic Authentication.
- Method: PUT
- Endpoint:
/users/{username}
Access to this endpoint requires authentication. You can provide authentication using either of the following methods:
Include a valid Bearer token in the Authorization header:
Authorization: Bearer your_access_token
This API endpoint allows deleting a user based on the provided username. Authentication is required through either a Bearer token or Basic Authentication.
- Method: DELETE
- Endpoint:
/users/{username}
Access to this endpoint requires authentication. You can provide authentication using either of the following methods:
Include a valid Bearer token in the Authorization header:
Authorization: Bearer your_access_token
This API endpoint allows fetching information for all users. Authentication is required through either a Bearer token or Basic Authentication.
- Method: GET
- Endpoint:
/users
Access to this endpoint requires authentication. You can provide authentication using either of the following methods:
Include a valid Bearer token in the Authorization header:
Authorization: Bearer your_access_token