This project is a Node.js application that provides authentication functionality, including sign up, sign in, sign out, password reset, and Google login/signup.
Visit the live site here
- Sign up with Email: Users can create an account by providing their email and password.
- Sign In: Users can sign in with their email and password.
- Sign Out: Users can sign out of their accounts.
- Reset Password: Users can reset their passwords after signing in.
- Encrypted Passwords: Passwords stored in the database are encrypted for security.
- Google Login/Signup: Users can sign in or sign up using their Google accounts.here
- Forgot Password: Users can reset their passwords via email.
- Password Strength Validation: Notifications are displayed for unmatching passwords during sign up and incorrect passwords during sign in.
- reCAPTCHA Integration: Extra points for enabling reCAPTCHA on both sign up and log in pages. here
To run the application, you need to set the following environment variables in a .env
file at the root of your project:
- PORT: Specifies the port number the application listens on.
- DB_URL: Specifies the MongoDB database URL.
- CLIENT_ID: Client ID for Google authentication.
- CLIENT_SECRET: Client Secret for Google authentication (sign in with Google).
- EMAIL: Email address to send Gmail messages.
- PASSWORD: Password for the Gmail account (use Gmail App Password if enabled).
- RECAPTCHA_SECRET_KEY: Secret key to use Google reCAPTCHA.
- 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/mydatabase
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
To run this project locally, follow these steps:
-
Clone the repository to your local machine:
git clone https://github.com/your-username/node-authentication.git
-
Navigate to the project directory:
cd node-authentication
-
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 Vivek Yadav
Feel free to contribute by submitting issues or pull requests!