An open API service indexing awesome lists of open source software.

https://github.com/apurva313/email-auth-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.
https://github.com/apurva313/email-auth-project

email-authentication email-sender express-js mongodb nodejs

Last synced: 3 days ago
JSON representation

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.

Awesome Lists containing this project

README

          

# 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](https://img.shields.io/badge/linkedin-0A66C2?style=for-the-badge&logo=linkedin&logoColor=white)](https://www.linkedin.com/apurva313)
[![github](https://img.shields.io/badge/github-181717?style=for-the-badge&logo=github&logoColor=white)](https://github.com/apurva313)

## Project Structure 🗂️

diagram

## Installation 🛠️

1. Clone the repository:
```sh
git clone https://github.com/apurva313/Email-auth-Project
```

2. Navigate to the project directory:
```sh
cd Email-auth-Project
```

3. Install the dependencies:
```sh
npm install
```

4. Create a [`.env`](command:_github.copilot.openRelativePath?%5B%7B%22scheme%22%3A%22file%22%2C%22authority%22%3A%22%22%2C%22path%22%3A%22%2FD%3A%2FCode%2FEmail-auth-Project%2F.env%22%2C%22query%22%3A%22%22%2C%22fragment%22%3A%22%22%7D%2C%22b5905f33-9e98-4c82-9582-923b1185c0cf%22%5D "d:\Code\Email-auth-Project\.env") file in the root directory and add the following environment variables:
```env
PORT=
MONGO_URI=
JWT_SECRET=
EMAIL_USER=
EMAIL_PASS=
```

## Running the Project 🚀

To start the project, run:
```sh
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:**
```json
{
"email": "apurvakumar@gmail.com",
"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:**
```json
{
"email": "apurva@gmail.com",
"token": "verification-token"
}
```
- **Response:**
- `200 OK` on success
- `400 Bad Request` if the token is invalid or expired

### Code Snippet

```javascript
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`](https://expressjs.com/): Web framework for Node.js
- [`mongoose`](https://mongoosejs.com/): MongoDB object modeling tool
- [`dotenv`](https://www.npmjs.com/package/dotenv): Loads environment variables from a `.env` file
- [`body-parser`](https://www.npmjs.com/package/body-parser): Middleware for parsing request bodies
- [`bcrypt`](https://www.npmjs.com/package/bcrypt): Library for hashing passwords
- [`jsonwebtoken`](https://www.npmjs.com/package/jsonwebtoken): Library for working with JSON Web Tokens
- [`nodemailer`](https://nodemailer.com/about/): 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.