Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mohsen104/session-based-authentication
This is a session-based authentication system built using Express.js and MongoDB. It includes secure authentication, user management, and developer utilities.
https://github.com/mohsen104/session-based-authentication
authentication backend express-js mongodb node-js session
Last synced: 25 days ago
JSON representation
This is a session-based authentication system built using Express.js and MongoDB. It includes secure authentication, user management, and developer utilities.
- Host: GitHub
- URL: https://github.com/mohsen104/session-based-authentication
- Owner: mohsen104
- Created: 2024-12-05T15:51:51.000Z (about 2 months ago)
- Default Branch: master
- Last Pushed: 2024-12-21T10:39:50.000Z (about 1 month ago)
- Last Synced: 2024-12-21T11:19:55.674Z (about 1 month ago)
- Topics: authentication, backend, express-js, mongodb, node-js, session
- Language: JavaScript
- Homepage:
- Size: 43 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Session Based Authentication
This is a **session-based authentication system** built using Express.js and MongoDB. It includes secure authentication, user management, and developer utilities.
## Features
- User authentication (via password or OTP)
- Secure session management with `express-session` and Redis
- User email and password update
- Developer tools for testing login methods and OTP generation
- Swagger documentation for API exploration## Prerequisites
1. **Redis**: This project requires Redis for session storage. Make sure Redis is installed and running on your system.
- [Install Redis](https://redis.io/docs/getting-started/installation/)2. **Node.js**: Install Node.js (version 14 or higher).
3. **MongoDB**: Ensure MongoDB is installed and running.
## Installation
1. Clone the repository:
```bash
git clone https://github.com/mohsen104/Session-Based-Authentication.git
cd Session-Based-Authentication
```2. Install dependencies:
```bash
npm install
```3. Create a `.env` file in the root directory and configure the following environment variables:
```env
NODE_ENV
PORT
MONGO_URI
COOKIE_PARSER_SECRET_KEY
JWT_SECRET_KEY
SESSION_SECRET_KEY
```4. Start the application:
- Development mode:
```bash
npm run dev
```- Production mode:
```bash
npm start
```## API Documentation
The API is documented using Swagger and can be accessed at:
```
http://localhost:3000/api-docs
```### Swagger Overview
- **Base URL**: `http://localhost:3000/api`
- **Tags**:
- `User`: Routes for user authentication and management
- `Dev`: Developer utilities## Scripts
- `npm run dev`: Run the app in development mode using `nodemon`.
- `npm start`: Run the app in production mode.## Dependencies
- **Production**:
- `express`: Web framework
- `express-session`: Session management
- `connect-redis`: Redis session store
- `mongoose`: MongoDB object modeling
- `bcryptjs`: Password hashing
- `helmet`: Security headers
- `cors`: Cross-origin resource sharing- **Development**:
- `dotenv`: Environment variable management
- `nodemon`: Development server reloader
- `swagger-jsdoc`: API documentation generator
- `swagger-ui-express`: Swagger UI for documentation