This project is a simple email authentication system built with Node.js, Express, and MongoDB. It allows users to register and verify their email addresses.
-
Clone the repository:
git clone https://github.com/apurva313/Email-auth-Project
-
Navigate to the project directory:
cd Email-auth-Project
-
Install the dependencies:
npm install
-
Create a
.env
file in the root directory and add the following environment variables:PORT= MONGO_URI= JWT_SECRET= EMAIL_USER= EMAIL_PASS=
To start the project, run:
npm start
This will start the server on the port specified in the .env file (default is 3000).
- URL:
/api/auth/register
- Method:
POST
- Description: Registers a new user.
- Request Body:
{ "email": "[email protected]", "password": "password123" }
- Response:
201 Created
on success400 Bad Request
if the email is already registered or if there are validation errors
- URL:
/api/auth/verify-email
- Method:
POST
- Description: Verifies the user's email address.
- Request Body:
{ "email": "[email protected]", "token": "verification-token" }
- Response:
200 OK
on success400 Bad Request
if the token is invalid or expired
const express = require('express');
const { register, verifyEmail } = require('../controllers/authController');
const router = express.Router();
router.post('/register', register);
router.post('/verify-email', verifyEmail);
module.exports = router;
express
: Web framework for Node.jsmongoose
: MongoDB object modeling tooldotenv
: Loads environment variables from a.env
filebody-parser
: Middleware for parsing request bodiesbcrypt
: Library for hashing passwordsjsonwebtoken
: Library for working with JSON Web Tokensnodemailer
: Library for sending emails
We welcome contributions to this project! If you would like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.
Please make sure to update tests as appropriate.
This project is licensed under the ISC License.