Skip to content

This project contains a complete authentication system using Node.js, Express, and MongoDB. It includes features like sign up, sign in, sign out, password reset, and social authentication (Google).

Notifications You must be signed in to change notification settings

ravikantsingh12/NodeJS-Authentication-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js Authentication System

This project contains a complete authentication system using Node.js, Express, and MongoDB. It includes features like sign up, sign in, sign out, password reset, and social authentication (Google). The project is structured to be scalable with separate components for models, controllers, and routes.

Live Site

Click here to visit the live site.

Features Implemented

  • Sign-up with Email: Create an account using your email and password.
  • Sign-in: Log into your account securely.
  • Sign Out: Log out of your session.
  • Reset Password: You can reset your passwords after signing in.
  • Encrypted Passwords: Passwords are securely stored using encryption.
  • Google Login/Signup: Sign in or sign up using your Google account.
  • Forgot Password: Reset your password via email.
  • Password Strength Validation: Notifications are displayed for unmatching passwords during sign up and incorrect passwords during sign in.
  • reCAPTCHA Integration: Protects against bot traffic on sign up and login pages.

Environment Variables

Before running the application locally, ensure you have set up the following environment variables in a .env file located at the root of your project:

  1. PORT: Specifies the port number the application listens on.
  2. DB_URL: MongoDB database connection URL.
  3. CLIENT_ID: Google OAuth client ID.
  4. CLIENT_SECRET: Google OAuth client secret (sign in with Google).
  5. EMAIL: Email address for sending emails.
  6. PASSWORD: App-specific password or regular password for the Gmail account.
  7. RECAPTCHA_SECRET_KEY: Google reCAPTCHA secret key.
  8. CLIENT_URL: URL to redirect after signing in with Google, e.g., "http://localhost:3000/auth/login/success".

Ensure that you have the appropriate values for each variable before running the application.

Example .env file:

PORT=3000
DB_URL=mongodb://localhost:27017/authdatabase
CLIENT_ID=your_client_id
CLIENT_SECRET=your_client_secret
EMAIL=your_email@gmail.com
PASSWORD=your_gmail_password
RECAPTCHA_SECRET_KEY=your_recaptcha_secret_key
CLIENT_URL=http://localhost:3000/auth/login/success

Folder

node-authentication/
├── config/                  # Configuration files
│   └── mongodb.js           # MongoDB configuration
│
├── controllers/             # Controller logic
├── models/                  # Database models
├── routes/                  # Route definitions
├── views/                   # EJS views
├── app.js                   # Express application setup
│
├── public/                  # Static assets
│
├── package.json             # NPM package configuration
├── README.md                # Project README file
├── .gitignore               # Git ignore configuration
└── .env                     # Environment variables file

Installation and Setup

Follow these steps to run the project locally:

  1. Clone the repository to your local machine:

    git clone https://github.com/your-username/nodejs-authentication-system.git
    
  2. Navigate into the project directory:

    cd node-authentication-system
  3. Install dependencies:

    npm install
    
  4. Start the server:

    npm start
  5. Open your web browser and visit http://localhost:3000 to access the application.

Dependencies required

  • Express.js
  • MongoDB
  • Passport.js
  • bcrypt
  • express-session
  • express-ejs-layouts
  • dotenv
  • nodemailer

Credits

This project was created by Ravikant Singh. Contributions via issues or pull requests are welcome!

Follow me on

About

This project contains a complete authentication system using Node.js, Express, and MongoDB. It includes features like sign up, sign in, sign out, password reset, and social authentication (Google).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published