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.
Click here to visit the live site.
- 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.
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:
- PORT: Specifies the port number the application listens on.
- DB_URL: MongoDB database connection URL.
- CLIENT_ID: Google OAuth client ID.
- CLIENT_SECRET: Google OAuth client secret (sign in with Google).
- EMAIL: Email address for sending emails.
- PASSWORD: App-specific password or regular password for the Gmail account.
- RECAPTCHA_SECRET_KEY: Google reCAPTCHA secret key.
- 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
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
Follow these steps to run the project locally:
-
Clone the repository to your local machine:
git clone https://github.com/your-username/nodejs-authentication-system.git
-
Navigate into the project directory:
cd node-authentication-system
-
Install dependencies:
npm install
-
Start the server:
npm start
-
Open your web browser and visit http://localhost:3000 to access the application.
- Express.js
- MongoDB
- Passport.js
- bcrypt
- express-session
- express-ejs-layouts
- dotenv
- nodemailer
This project was created by Ravikant Singh. Contributions via issues or pull requests are welcome!