@bhooai/nexus-auth
v0.1.5
Published
One cohesive security + identity unit: CORS, CSRF, security headers, rate limiting, password hashing, JWT auth, sessions, RBAC, and Google + Facebook OAuth2.
Downloads
487
Readme
@bhooai/nexus-auth
One cohesive security + identity unit: CORS, CSRF, security headers, rate limiting, password hashing, JWT auth, sessions, RBAC, and Google + Facebook OAuth2.
Exports
- CORS —
cors({ origin, credentials })with preflight short-circuit andVary: Origin. - CSRF —
csrf({ trustedOrigins })double-submit token (HttpOnlynexus_csrfcookie +x-csrf-tokenheader);issueCsrfToken(ctx, { trustedOrigins }). Safe methods issue a fresh token; unsafe methods runcheckOrigin+ double-submit. Applies to all unsafe methods (incl.POST /graphqland/payments) and to the WS upgrade. - headers —
securityHeaders()(helmet-equivalent). - rateLimit —
rateLimit({ windowMs, max })(in-memory; Redis backend innexus-cache). - jwt / session / password —
AuthService,MemorySessionStore,hashPassword/verifyPassword, access + refresh token rotation. - rbac — role checks.
- oauth —
buildGoogleAuthUrl(with PKCE),exchangeGoogleCode,fetchGoogleProfile, and the Facebook equivalents. - middleware —
authToken(service, { cookieName, allowCookie, required }),requireAuth(),setAuthCookies,clearAuthCookies.
authToken's first argument is theAuthServiceinstance; options are the 2nd.
CSRF note
With a non-empty trustedOrigins, every unsafe request must carry an Origin
header that exactly matches a trusted origin (including the port) and a
matching x-csrf-token. API clients that don't send Origin (e.g. Playwright's
APIRequestContext) must add it explicitly — see the e2e/integration tests.
