Skip to content

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.

Notifications You must be signed in to change notification settings

apurva313/Email-auth-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Email Authentication Project 📧🔒

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.

🚀 About Me

linkedin github

Project Structure 🗂️

Installation 🛠️

  1. Clone the repository:

    git clone https://github.com/apurva313/Email-auth-Project
  2. Navigate to the project directory:

    cd Email-auth-Project
  3. Install the dependencies:

    npm install
  4. Create a .env file in the root directory and add the following environment variables:

    PORT=
    MONGO_URI=
    JWT_SECRET=
    EMAIL_USER=
    EMAIL_PASS=

Running the Project 🚀

To start the project, run:

npm start

This will start the server on the port specified in the .env file (default is 3000).

API Endpoints 🌐

Register 📝

  • URL: /api/auth/register
  • Method: POST
  • Description: Registers a new user.
  • Request Body:
    {
        "email": "[email protected]",
        "password": "password123"
    }
  • Response:
    • 201 Created on success
    • 400 Bad Request if the email is already registered or if there are validation errors

Verify Email ✅

  • 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 success
    • 400 Bad Request if the token is invalid or expired

Code Snippet

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;

Dependencies 📦

  • express: Web framework for Node.js
  • mongoose: MongoDB object modeling tool
  • dotenv: Loads environment variables from a .env file
  • body-parser: Middleware for parsing request bodies
  • bcrypt: Library for hashing passwords
  • jsonwebtoken: Library for working with JSON Web Tokens
  • nodemailer: Library for sending emails

Contributing 🤝

We welcome contributions to this project! If you would like to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes.
  4. Commit your changes (git commit -m 'Add some feature').
  5. Push to the branch (git push origin feature-branch).
  6. Open a pull request.

Please make sure to update tests as appropriate.

License 📄

This project is licensed under the ISC License.

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published