-
Notifications
You must be signed in to change notification settings - Fork 0
Auth: JWT middleware + utilities (authenticate/authorize) #121
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Auth System — Step 2 (Backend)
Replace static API key middleware with JWT-based auth.
New middleware:
authenticate(req, res, next)— verify JWT, attachreq.userauthorize(...roles)— check user has required role for the farm- Dev mode bypass: if
JWT_SECRETunset andNODE_ENV !== 'production', inject synthetic admin
JWT strategy:
- Access token: HS256, 15min lifetime, in-memory only
- Refresh token: 48 random bytes, bcrypt-hashed in DB, 30-day lifetime
- Token rotation with reuse detection
Dependencies: jsonwebtoken, bcrypt (or bcryptjs)
Implementation:
- Rewrite
backend/src/middleware/auth.js - JWT sign/verify utilities
- Refresh token hashing + rotation logic
- Dev mode bypass preserved
- Production startup error if
JWT_SECRETmissing - Auth-specific rate limiters (login: 10/15min, register: 5/hr)
Depends on: DB migration
Design doc: docs/AUTH.md
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request