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

https://github.com/amritasri10/registration-form

A full-stack user authentication system built with Node.js, Express, and MongoDB, featuring OTP-based email verification, Google OAuth login, JWT authentication, and session management. Includes a clean frontend with HTML, CSS, and JavaScript for seamless user experience.
https://github.com/amritasri10/registration-form

authentication backend expressjs fronted full-stack google-oauth html-css-javascript jwt mongodb mongoosejs mvc-architecture nodejs nodemailer passportjs responsive-design rest-api session-management user-authentication web-development

Last synced: 3 months ago
JSON representation

A full-stack user authentication system built with Node.js, Express, and MongoDB, featuring OTP-based email verification, Google OAuth login, JWT authentication, and session management. Includes a clean frontend with HTML, CSS, and JavaScript for seamless user experience.

Awesome Lists containing this project

README

          

# ๐Ÿ“ Registration Form Project

The **Registration Form Project** is a complete user authentication system developed using **Node.js**, **Express**, and **MongoDB**. It provides both manual registration with **OTP-based email verification** and **Google OAuth login** through **Passport.js**, ensuring flexible and secure access for users.

Once registered or logged in, users are authenticated using **JWT tokens**, and their sessions are managed effectively to maintain persistent login states. The **frontend** is built with clean and responsive **HTML, CSS, and vanilla JavaScript**, offering a smooth user experience.

On the **backend**, robust logic ensures secure data handling, user validation, and integration with external services like email and Google OAuth. This project serves as a practical example of building modern authentication flows in full-stack web development.

---

## ๐Ÿš€ Features

- User registration with **OTP verification via email**
- **Google OAuth 2.0** login/signup
- **Welcome email** sent after successful registration
- **JWT-based** secure login system
- **Sessions managed** using `express-session`
- Uses **MongoDB Atlas** for cloud database
- Organized MVC structure for maintainability

---

## ๐Ÿ—‚ Project Structure

```
registration-form/
โ”œโ”€โ”€ config/ #Passport.js config (Google Auth)
โ”œโ”€โ”€ controllers/ # Auth logic: OTP & Google
โ”‚ โ”œโ”€โ”€ authController.js
โ”‚ โ””โ”€โ”€ googleAuthController.js
โ”œโ”€โ”€ middleware/ # Custom middleware
โ”œโ”€โ”€ models/
โ”‚ โ””โ”€โ”€ User.js # Mongoose User model
โ”œโ”€โ”€ public/ # Static frontend (HTML, CSS)
โ”‚ โ”œโ”€โ”€ index.html # Registration form
โ”‚ โ”œโ”€โ”€ login.html # Login page
โ”‚ โ”œโ”€โ”€ verify-otp.html # OTP verification
โ”‚ โ”œโ”€โ”€ success.html # Login success
โ”‚ โ”œโ”€โ”€ error.html # Error screen
โ”‚ โ””โ”€โ”€ styles.css # Styling
โ”œโ”€โ”€ screenshots/
โ”‚ โ”œโ”€โ”€ registration-page.png
โ”‚ โ”œโ”€โ”€ otp-verification.png
โ”‚ โ”œโ”€โ”€ login-page.png
โ”‚ โ”œโ”€โ”€ success-page.png
โ”‚ โ”œโ”€โ”€ google-auth-email.png
โ”œโ”€โ”€ routes/
โ”‚ โ””โ”€โ”€ authRoutes.js # Express routes
โ”œโ”€โ”€ utils/
โ”‚ โ””โ”€โ”€ sendEmail.js # Utility to send emails
โ”œโ”€โ”€ .env # Environment variables
โ”œโ”€โ”€ server.js # Main server entry point
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ README.md
```

---

## โš™๏ธ Technologies Used

- **Frontend**: HTML, CSS, JavaScript
- **Backend**: Node.js, Express.js
- **Database**: MongoDB Atlas (via Mongoose)
- **Authentication**: JWT, Google OAuth 2.0, OTP
- **Email Service**: Nodemailer (SMTP)
- **Session**: express-session

---

## ๐Ÿ” Authentication Flow

### ๐Ÿ”ธ Manual Registration

1. User visits `/index.html` and Register the form.
2. An OTP is sent to the provided email using `sendEmail.js`.
3. User enters OTP at `/verify-otp.html`.
4. On successful verification:
- Account is created in MongoDB.
- Welcome email is sent.
- User is redirected to `/login.html`.

### ๐Ÿ”ธ Login

1. User enters email & password at `/login.html`.
2. Server validates credentials.
3. On success:
- JWT token is issued.
- Session is created.
- User is redirected to `/success.html`.

### ๐Ÿ”ธ Google OAuth

1. User clicks **Google Login**.
2. Google OAuth flow via Passport.js.
3. New account is created (if first login).
4. Welcome email sent.
5. User redirected to `/success.html`.

---

### ๐Ÿ–ผ๏ธ Screenshots

#### Registration Page
![Registration Page](./screenshots/registration-page.png)

#### OTP Verification Page
![OTP Verification](./screenshots/otp-verification.png)

#### Login Success Page
![Login Page](./screenshots/login-page.png)

#### Success Page
![Success Page](./screenshots/success-page.png)

#### Google OAuth Welcome Email
![Google OAuth Mail](./screenshots/google-auth-emai.png)

---

## ๐Ÿ“ฌ Email Integration

- OTP emails are triggered during registration.
- Welcome emails are sent after:
- Successful manual registration
- Google OAuth-based registration

---

## ๐Ÿ“Œ API Endpoints

### ๐Ÿ”น `POST /register`
Registers a new user and sends OTP to email.

### ๐Ÿ”น `POST /verify-otp`
Verifies OTP and creates the user account.

### ๐Ÿ”น `POST /login`
Authenticates user using email and password.

### ๐Ÿ”น `GET /auth/google`
Initiates Google OAuth login.

### ๐Ÿ”น `GET /auth/google/callback`
Google callback URL (used internally by Passport.js).

---

## ๐Ÿ“ฆ Setup Instructions

### ๐Ÿ”น Prerequisites:

- [Node.js installed](https://nodejs.org/)
- [MongoDB Atlas account](https://www.mongodb.com/cloud/atlas)
- [Gmail account (or SMTP credentials)](https://support.google.com/mail/answer/7126229?hl=en)

### ๐Ÿ”น Installation

1. Clone the repo:

`git clone https://github.com/Amritasri10/registration-form.git
cd registration-form`

2. Install dependencies:

`npm install`

3. Create .env file:

`PORT=5000
MONGO_URI=your_mongo_connection_string
JWT_SECRET=your_jwt_secret
EMAIL_USER=your_email@example.com
EMAIL_PASS=your_email_password
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret`

4. Start the app:

`node server.js`

5. Open your browser and visit:

`http://localhost:5000`

---

## ๐Ÿงช Testing Instructions

- Manual Register โ†’ OTP โ†’ Login โ†’ Success
- Try wrong OTP โ†’ Should show error
- Try Google OAuth โ†’ Should redirect and welcome
- Check email inbox for OTP and Welcome mails

---

## ๐Ÿ“„ License

This project is licensed under the MIT License - feel free to use it for personal or academic projects.

---

## Author

Connect with me on:
[LinkedIn ](https://www.linkedin.com/in/amrita-srivastava10/) | [GitHub](https://github.com/Amritasri10)