r/node • u/eyobhailu • 16d ago
Stop passing req.user everywhere: I ported Spring Security's architecture to Express
If you have built an Express API, you know the frustration: you authenticate a token, attach data to req.user, and spend the rest of the day passing the req object down through services, repositories, and helper functions.
The usual alternative is migrating to NestJS just to get decent guards and decorators.
I built express-spring-security to bring that clean architecture to Express 5 and TypeScript without the framework bloat:
- Ambient Context: Access the authenticated user anywhere in your backend via Node's AsyncLocalStorage without passing the req object around.
- Single Security Chain: Define all your public, protected, and role-based routes in one central configuration.
- Method-Level Authorization: Lock down controller methods with declarative `@PreAuthorize` role and authority checks.
It is open source on GitHub and npm under `express-spring-security` (link is in the comments below).
Would love to hear your feedback and how you are currently handling auth in your Express apps!