Hmm during refactoring my project, I was suffering about structure of directory and how to render authentication.
first of all, make directories which are library and routers..
roject/
├─ lib/ # Utilities and core services
│ ├─ constants.js # Env variables, JWT secret, token expiry, etc.
│ ├─ prisma.js # PrismaClient singleton (optional but useful)
│ ├─ token/ # JWT helpers (sign, verify, refresh)
│ └─ passport/ # All authentication strategies
│ ├─ localStrategy.js # For username/password login
│ ├─ jwtStrategy.js # For JWT verification
│ ├─ oauthStrategy.js # For Google/GitHub/etc.
│ └─ index.js # Register all strategies with passport
│
├─ routers/ # Route definitions
│ ├─ auth.js # Register, login, logout endpoints
│ ├─ protected.js # Endpoints that require authentication
│ └─ index.js # Combine routers into a single entry
│
├─ prisma/
│ └─ schema.prisma # Database schema
│
├─ server.js # App entrypoint
└─ package.json
🔄 Request Flow Example
user register via api/auth
User logs in via /auth/login
User accesses protected route /protected/profile
Top comments (0)