A modern, multi-provider authentication system built with Node.js, Express, TypeScript, Passport.js, MongoDB, and Redis.
- Building a TypeScript REST API with OOP
- Node and Passport.js GitHub Authentication
- Advanced Error Handling in Node.js
- Google Auth with Passport.js
- Dotenv for Node.js
- Redis with TypeScript
A robust authentication system supporting:
- 🔑 Local, GitHub, Google, Twitter, LinkedIn, Facebook logins
- 🛡️ Secure session management with Redis
- 🗄️ MongoDB for user data
- 🧩 Modular, scalable TypeScript codebase
git clone https://github.com/your-repo/auth.git
cd auth
npm install
# or
yarn installCreate .env.development, .env.test, .env.staging, and .env.production as needed and add the required environment variables.
npm run dev
# or
yarn devdocker-compose upAuth/
├── src/
│ ├── config/ # App configuration (passport, cors, etc.)
│ ├── controllers/ # Route controllers
│ ├── interfaces/ # TypeScript interfaces/types
│ ├── middlewares/ # Express middlewares
│ ├── models/ # Mongoose models
│ ├── routes/ # Express route definitions
│ ├── services/ # Passport strategies, business logic
│ ├── utils/ # Utility functions
│ ├── views/ # EJS templates
│ ├── app.ts # Express app setup
│ ├── server.ts # Server entry point
├── public/ # Static assets (images, CSS, JS)
├── dist/ # Compiled output
├── .env.development # Environment variables
├── docker-compose.yml # Docker config
└── package.json
| Route | Method | Description | Restriction |
|---|---|---|---|
/api/v1/auth/login |
GET | Login page | Public |
/api/v1/auth/register |
GET | Registration page | Public |
/api/v1/auth/logout |
GET | Logout | Authenticated only |
/api/v1/auth/profile |
GET | User profile | Authenticated only |
/api/v1/auth/github |
GET | GitHub OAuth start | Public |
/api/v1/auth/github/callback |
GET | GitHub OAuth callback | Public |
/api/v1/auth/google |
GET | Google OAuth start | Public |
/api/v1/auth/google/callback |
GET | Google OAuth callback | Public |
/api/v1/auth/twitter |
GET | Twitter OAuth start | Public |
/api/v1/auth/twitter/callback |
GET | Twitter OAuth callback | Public |
/api/v1/auth/linkedin |
GET | LinkedIn OAuth start | Public |
/api/v1/auth/linkedin/callback |
GET | LinkedIn OAuth callback | Public |
/api/v1/auth/facebook |
GET | Facebook OAuth start | Public |
/api/v1/auth/facebook/callback |
GET | Facebook OAuth callback | Public |
/api/v1/user/me |
GET | Current user info | Authenticated only |
/api/v1/user/update |
POST | Update user profile | Authenticated only |
- Public: Anyone can access (login, register, OAuth start/callback)
- Authenticated only: User must be logged in (profile, logout, user info)
- Admin only: (If implemented) Only admin users
MONGO_URI– MongoDB connection stringREDIS_URL– Redis connection stringPORT– Server portGITHUB_CLIENT_ID,GITHUB_CLIENT_SECRET,GITHUB_CALLBACK_URLGOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRET,GOOGLE_CALLBACK_URLTWITTER_CONSUMER_KEY,TWITTER_CONSUMER_SECRET,TWITTER_CALLBACK_URLLINKEDIN_CLIENT_ID,LINKEDIN_CLIENT_SECRET,LINKEDIN_CALLBACK_URLFACEBOOK_CLIENT_ID,FACEBOOK_CLIENT_SECRET,FACEBOOK_CALLBACK_URL