Welcome to the Auth System Starter—an open-source, feature-rich authentication boilerplate built with Node.js, Express.js, and MongoDB. This project supports multiple authentication methods (including manual signup/login with JWT and social logins using Passport.js), role-based access control, email verification, and more.
This repository is a perfect starting point for developers looking to implement authentication in their applications quickly. Feel free to contribute, fine-tune, and customize as per your needs!
- 🌐 Authentication Options:
- Manual login/signup with JWT.
- Social logins with Google, Facebook, GitHub, and Apple ID.
- 🛡 Role-Based Access Control (RBAC):
- Create and manage custom roles.
- Assign multiple roles to users.
- 📧 Email Verification:
- Secure email verification using NodeMailer.
- 🔐 Secure Password Storage:
- Hashing with
bcrypt
.
- Hashing with
- 🛠 Modular Project Structure:
- Controllers for business logic, helpers for utilities.
- 📖 Swagger Documentation:
- API routes fully documented for easy integration.
- 🚀 Scalable and Open Source:
- Designed for extensibility and contributions from the community.
Here’s an organized project structure to help you navigate the codebase:
📂 auth-system-starter
├── 📁 config
│ └── db.js # MongoDB connection setup
│ └── passport.js # Passport strategies configuration
├── 📁 controllers
│ └── authController.js # Handles authentication logic
│ └── userController.js # Manages user-related actions
├── 📁 helpers
│ └── sendEmail.js # Email utility for sending emails
├── 📁 middlewares
│ └── authMiddleware.js # Middleware for role-based access and JWT validation
├── 📁 models
│ └── User.js # Mongoose schema for User
│ └── Role.js # Mongoose schema for Role
├── 📁 routes
│ └── authRoutes.js # Routes for authentication and authorization
│ └── userRoutes.js # Routes for user management
├── 📁 utils
│ └── swagger.js # Swagger setup for API documentation
├── .env.example # Environment variables
├── README.md # Project documentation
├── package.json # Project dependencies and scripts
└── index.js # Entry point of the application
Follow these steps to get this project up and running:
npx create-express-auth-starter
Install using your preferred package manager:
npm install
# or
yarn install
# or
pnpm install
Create a .env
file in the project root and add the following:
PORT=5000
MONGO_URI=your-mongodb-connection-string
JWT_SECRET=your-jwt-secret
EMAIL_USER=[email protected]
EMAIL_PASSWORD=your-email-password
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
FACEBOOK_CLIENT_ID=your-facebook-client-id
FACEBOOK_CLIENT_SECRET=your-facebook-client-secret
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret
APPLE_CLIENT_ID=your-apple-client-id
APPLE_CLIENT_SECRET=your-apple-client-secret
CLIENT_URL=http://localhost:3000 # Replace with your frontend URL
- Go to https://console.cloud.google.com/apis/dashboard
- Click on create New Project
- Give a name
- Go to the project's dashboard using this dropdown
- Go to Library Section and search for Google People API and enable it
- Go to the credentials and click on create credentials
- Click on OAuth Client ID and then on Configure Consent Screen
- Click on External and then create
- Configure your app
- Once set Now go to the same Create OAuth Client ID Again this time you will be able to create the application
- Add the redirect url as given
- Now Copy and Paste
- You can hit the google auth by GET Request over http://localhost:5000/api/auth/google
npm run dev
# or
yarn dev
# or
pnpm run dev
The server will start on http://localhost:5000
.
The API documentation is available at:
http://localhost:5000/api-docs
Swagger is pre-configured to provide an interactive interface for testing and understanding the API endpoints.
We welcome contributions to improve this project! Here’s how you can help:
- Fork this repository.
- Create a feature branch (
git checkout -b feature-name
). - Commit your changes (
git commit -m "Add feature"
). - Push to the branch (
git push origin feature-name
). - Open a pull request.
To make this project available to the public as a package:
- Ensure
package.json
has the relevant metadata:{ "name": "auth-system-starter", "version": "1.0.0", "description": "A starter project for authentication with Passport.js, JWT, and role-based access control.", "main": "server.js", "keywords": ["authentication", "passport.js", "jwt", "nodejs", "express"], "author": "Faraz Ahmad <[email protected]>", "license": "MIT" }
This project is licensed under the MIT License. Feel free to use, modify, and distribute it.
- 🌟 Star this repository to show your support.
- 💬 Join discussions and share your ideas or issues.
- 🛠 Contribute to make it even better.
Let’s build amazing applications together! 🚀