Next.js Middleware — Authentication and Routing
Use middleware for authentication, request logging, and conditional routing.
14 articles
Use middleware for authentication, request logging, and conditional routing.
Implement secure authentication with NextAuth.js v5 supporting OAuth, credentials, and magic links.
Implement JWT authentication securely. Token generation, verification, refresh tokens, and best practices.
Master OAuth 2.0 for third-party authentication. Authorization Code flow, social login, and best practices.
Master Passport.js for flexible authentication. Local strategy, social login, and middleware integration.
Secure your APIs in 2026: OWASP Top 10 for APIs, SQL injection prevention, JWT best practices, CORS configuration, input validation, rate limiting, and security headers. With code examples.
Design API gateways for rate limiting, JWT auth, request aggregation, and versioning. Learn gateway vs service mesh and Kong vs cloud vendors.
Server A issues a JWT. Server B validates it 2 seconds later but thinks the token was issued in the future — invalid. Or a token that should be expired is still accepted because the validating server''s clock is 5 minutes behind. Clock skew causes authentication failures and security holes.
Prevent algorithm confusion attacks, implement safe key rotation, detect token theft with refresh token families, and secure JWTs with binding and revocation strategies.
Understand JWT stateless tradeoffs, session cookie security, token refresh rotation, and hybrid approaches. Learn when to use JWTs for service-to-service auth and why short TTLs matter.
Master PKCE (Proof Key for Public Clients) for JavaScript SPAs and mobile apps. Learn code verifier generation, state parameters, token storage, refresh flows, and scope design.
Deep dive into OWASP API Security Top 10 vulnerabilities with production-ready fixes: BOLA, broken auth, data exposure, rate limiting, function level auth, and more.
Master WebAuthn registration and authentication flows. Learn resident credentials for usernameless login, device binding, attestation verification, and production-ready Node.js implementations.
Build zero trust backend with mTLS, SPIFFE identities, service-to-service JWT tokens, request signing, and dynamic database credentials via Vault.