Authentication Project using MVC architecture
This project is an authentication system built using ExpressJs with both manual and Google authentication options. The project follows the MVC (Model-View-Controller) architecture and uses a Singleton pattern for user storage.
Features
- Manual Authentication: Users can sign up and log in with a username and password.
- Google Authentication: Users can log in using their Google account.
- JWT (JSON Web Token): Tokens are generated and validated for session management.
- Singleton Pattern for User Storage: Users are stored in a Singleton class, eliminating the need for a database.
- Middleware: Custom middleware checks if a JWT token is still valid. If the token is invalid or expired, the user is redirected to the signup page.
- Express Routers: Used to manage routes for authentication and other parts of the application.
Project Structure
.
├── controllers
│ ├── google.controller.js
| ├── logout.controller.js
| ├── signin.controller.js
├── models
│ ├── userSingleton.js
├── routes
│ ├── routes.js
| ├── google.routes.js
├── views
│ ├── signup.ejs
│ ├── home.ejs
├── middlewares
│ ├── authorization.js
├── utils
| ├── jwt.sign.js
├── app.js
└── README.md
- controllers: Contains the logic for handling requests and responses.
- models: Contains the Singleton class for managing users.
- views: Contains the EJS files for rendering the signup and login pages.
- routes: Contains the route definitions for authentication.
- middlewares: Contains custom middleware for validating JWT tokens.
Getting Started
Prerequisites
- Node.js
- npm ### Installation
- Clone the repository:
git clone git@github.com:ADILRAQ/Authentication-Express-MVC.git Navigate to the project directory:
cd Authentication-Express-MVC.git
Install dependencies:
npm install
this video explaining how to get the keys for .env file link
Running the Project, to start the development server, run:
npm start
Usage
Navigate to http://localhost:3000/signup to sign up.
Navigate to http://localhost:3000/ to go home page.
Log in or sign up for Devpost to join the conversation.