This is a complete authentication system built with Node.js that can serve as a starter code for creating new applications. It includes features like user sign-up, sign-in, sign-out, reset password, and social authentication (Google login/signup). The system also handles encryption of passwords stored in the database and displays appropriate notifications for unmatching passwords during sign-up and incorrect passwords during sign-in. Additionally, it has a bonus feature for handling forgot passwords.
Follow these steps to set up the project on your local system:
- Node.js and npm should be installed on your system.
[git clone](https://github.com/your-username/nodejs-authentication.git)
cd nodejs-authentication
npm install
Create a .env file in the root directory of the project and add the following configuration:
# Replace these values with your actual configurations
PORT=3000
MONGO_URI=mongodb://localhost:27017/auth_app
SECRET_KEY=your_secret_key
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
RECAPTCHA_SITE_KEY=your_recaptcha_site_key
RECAPTCHA_SECRET_KEY=your_recaptcha_secret_key
npm start
The application should now be running on
http://localhost:3000
.
The project follows a scalable folder structure to separate models, controllers, and routes. Here's the overview:
nodejs-authentication/
├── assets/
│ ├── css/
│ │ ├── bootstrap.min.css
│ ├── images/
| | ├── backgroundimg.jpg
├── config/
│ ├── checkAuth.js
│ └── keys.js
│ ├── passport.js
├── controllers/
│ ├── authController.js
├── models/
│ ├── User.js
├── node_modules/
│ ├── node modules dependencies
├── routes/
│ ├── authRoutes.js
│ └── indexRoutes.js
├── views/
│ ├── dashboardPage.ejs
│ ├── forgotPasswordPage.ejs
│ ├── layout.ejs
│ ├── loginPage.ejs
│ ├── messages.ejs
│ ├── userRegistrationPage.ejs
│ ├── resetPasswordPage.ejs
│ ├── WelcomePage.ejs
├── .gitignore
├── index.js
├── package-lock.json
├── package.json
The application's pages are designed to look good and are inspired by authentication systems used by popular services like Google and Facebook. The design uses Bootstrap for responsive layouts and Noty for displaying notifications.
User passwords are securely encrypted before being stored in the database. This ensures that sensitive information remains protected even in the event of a data breach.
The system includes a "Forgot Password" feature that allows users to reset their password. Users can either receive a random password via email or a reset password link, which expires after a certain time (preferred).
Please ensure not to include any passwords or sensitive information in your git commits. Use environment variables and a .env file to manage sensitive data.