A Node.js starter template for KOOMPI OAuth authentication with TypeScript, Express, MongoDB, and JWT.
- KOOMPI OAuth 2.0 integration with PKCE
- JWT authentication
- TypeScript + Express
- MongoDB with Mongoose
- Hot reload with nodemon + tsx
- CORS enabled
- Node.js (v18+)
- MongoDB
- KOOMPI OAuth credentials from dash.koompi.org
npm installCopy .env.example to .env and configure:
PORT=3000
MONGODB_URI=mongodb://localhost:27017/koompi-oauth
JWT_SECRET=your-secret-key
JWT_EXPIRATION=24h
KOOMPI_CLIENT_ID=your-client-id
KOOMPI_CLIENT_SECRET=your-client-secret
KOOMPI_REDIRECT_URI=http://localhost:3000/api/oauth/callbacknpm run devServer runs at http://localhost:3000
src/
├── config/ # Configuration files
├── controllers/ # Request handlers
├── middleware/ # Auth middleware
├── models/ # Database models
├── routes/ # API routes
├── types/ # TypeScript types
└── utils/ # Utilities
GET /api/oauth/login- Start OAuth flowGET /api/oauth/callback- OAuth callback
GET /api/auth/me- Get current user (requires JWT)
- User visits
/api/oauth/login - Redirects to KOOMPI OAuth
- User authorizes
- KOOMPI redirects to
/api/oauth/callback - Server exchanges code for token
- Server creates/updates user in DB
- Returns JWT to client
{
userId: string; // KOOMPI user ID (unique)
name?: string;
firstName?: string;
lastName?: string;
username?: string;
profile?: string;
email?: string; // Requires scope
phone?: string; // Requires scope
telegramId?: number; // Requires scope
walletAddress?: string; // Requires scope
}// Login
window.location.href = "http://localhost:3000/api/oauth/login";
// Get profile
const token = localStorage.getItem("token");
const response = await fetch("http://localhost:3000/api/auth/me", {
headers: { Authorization: `Bearer ${token}` },
});npm run dev # Development with hot reload
npm run build # Build for production
npm start # Run production buildISC