DEV Community

Jun Oh Lee
Jun Oh Lee

Posted on

What the hell is authentication system in node?

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

Enter fullscreen mode Exit fullscreen mode

🔄 Request Flow Example

  1. user register via api/auth

  2. User logs in via /auth/login

  3. User accesses protected route /protected/profile

Top comments (0)