Web Authentication
Purpose
Plan how users prove identity and how the app carries that proof: the session/token model, where credentials live in the browser, how SSR and middleware see auth state, and the login/refresh/logout lifecycle. Enforcement is server-side, always.
When to Use
- When the app has any authenticated surface (customer app, dashboard).
- When reviewing or replacing an existing auth setup (
existing-web-audit findings).
- Not for role/permission gating (
web-authorization) or backend identity design.
Inputs
- Auth requirements: providers (email/password, OAuth/OIDC, SSO), MFA needs, session length.
- Backend boundary (
web-api-integration) and framework foundation (SSR changes the options).
- Compliance/security constraints (
../../security-review, ../../../system/SECURITY_RULES.md).
Discovery Questions
- Build on a managed provider (Auth0/Clerk/Supabase/NextAuth-style) or against an existing backend's auth — what does the evaluation say?
- Cookie sessions or bearer tokens? Same-origin or cross-origin API (cookie scope, CORS credentials)?
- Does SSR need the user (personalized server render), or is auth purely client-visible?
- Session lifetime, refresh policy, and "log out everywhere" requirements?
Responsibilities
Credential input rules (email normalization, password policy, confirm match) come from ../../auth-form-validation — one schema, enforced on the server too.
Decide the credential carrier: prefer httpOnly, Secure, SameSite cookies for browser apps; treat localStorage-held tokens as XSS-readable and justify any use.
Plan CSRF protection whenever cookies authenticate state-changing requests (SameSite plus token where needed).
Plan SSR/middleware auth on Next.js: reading the session in middleware/server components, redirect flow for protected pages, no auth-only content leaking into static output.
Evaluate managed providers vs self-managed as a decision with trade-offs (cost, lock-in, MFA/SSO needs).
Define the lifecycle: login, refresh (single-flight, rotation), logout (server-side invalidation, not just client state clearing), session expiry UX.
Keep client auth state a reflection of the server's decision — a hint for UX, never the gate.
Required Workflow
- Gather providers, session, and compliance requirements.
- Choose carrier + CSRF strategy against the backend origin layout.
- Plan SSR/middleware integration (Next.js) or SPA boot auth check (Vite).
- Define login/refresh/logout flows and failure UX.
- Record the plan for Gate 2; route enforcement review to
../../security-review.
Decision Rules
- Default to httpOnly cookie sessions for same-origin apps; bearer tokens make sense mainly when a separate API/multiple clients demand them — then plan storage and refresh explicitly.
- Any secret the browser JS can read is compromised under XSS — design as if XSS happens (
../../security-review).
- Middleware/route protection is routing UX; every API/server action re-checks identity itself.
- Managed provider vs self-managed is a recorded evaluation, not a default either way.
Rules
- No credentials, tokens, or session secrets in logs, error reports, or public env vars.
- Logout invalidates server-side; a cleared client store alone is not logout.
- Auth pages and redirects must not create open-redirect vectors (validate return paths).
Anti-Patterns
- JWTs in localStorage by habit, with no XSS story.
- Client-side "isLoggedIn" checks guarding data the API serves unauthenticated.
- Refresh logic that fans out (one refresh per parallel 401).
- Rolling custom crypto/session formats instead of vetted mechanisms.
Validation Checklist
Definition of Done
A recorded authentication plan — provider decision, credential carrier, CSRF posture, SSR integration, and full session lifecycle — where every enforcement point is server-side and the client only reflects it.
Related Skills
web-authorization, web-api-integration, web-routing, ../../security-review, ../../environment-audit, dashboard-permissions, nextjs-foundation.
Related Knowledge
../../../knowledge/ (identity model, compliance constraints).
Related References
../../../references/web/ (auth flow notes — when populated).
Context Loading Guidance
- Requires: auth requirements, backend/origin layout, framework foundation.
- Does not require: UI detail, unrelated feature skills.
- May load:
web-authorization next; ../../security-review for the enforcement review.
- Stop when: the auth plan is recorded for approval.
Token Efficiency Guidance
Decide from the origin/requirements summary. Record the model as carrier + lifecycle + enforcement points; don't restate general auth theory.
1---2name: web-authentication3description: Use to plan web authentication — session vs token model, httpOnly cookies vs localStorage risks, CSRF, SSR/middleware auth on Next.js, OAuth/managed-provider evaluation, refresh flow, and logout. The server enforces authentication; client auth state is a UX hint.4---56# Web Authentication78## Purpose910Plan how users prove identity and how the app carries that proof: the session/token model, where credentials live in the browser, how SSR and middleware see auth state, and the login/refresh/logout lifecycle. Enforcement is server-side, always.1112## When to Use1314- When the app has any authenticated surface (customer app, dashboard).15- When reviewing or replacing an existing auth setup (`existing-web-audit` findings).16- **Not** for role/permission gating (`web-authorization`) or backend identity design.1718## Inputs1920- Auth requirements: providers (email/password, OAuth/OIDC, SSO), MFA needs, session length.21- Backend boundary (`web-api-integration`) and framework foundation (SSR changes the options).22- Compliance/security constraints (`../../security-review`, `../../../system/SECURITY_RULES.md`).2324## Discovery Questions2526- Build on a managed provider (Auth0/Clerk/Supabase/NextAuth-style) or against an existing backend's auth — what does the evaluation say?27- Cookie sessions or bearer tokens? Same-origin or cross-origin API (cookie scope, CORS credentials)?28- Does SSR need the user (personalized server render), or is auth purely client-visible?29- Session lifetime, refresh policy, and "log out everywhere" requirements?3031## Responsibilities3233- Credential **input rules** (email normalization, password policy, confirm match) come from `../../auth-form-validation` — one schema, enforced on the server too.3435- Decide the **credential carrier**: prefer **httpOnly, Secure, SameSite cookies** for browser apps; treat localStorage-held tokens as XSS-readable and justify any use.36- Plan **CSRF protection** whenever cookies authenticate state-changing requests (SameSite plus token where needed).37- Plan **SSR/middleware auth** on Next.js: reading the session in middleware/server components, redirect flow for protected pages, no auth-only content leaking into static output.38- Evaluate **managed providers vs self-managed** as a decision with trade-offs (cost, lock-in, MFA/SSO needs).39- Define the **lifecycle**: login, refresh (single-flight, rotation), logout (server-side invalidation, not just client state clearing), session expiry UX.40- Keep client auth state a **reflection** of the server's decision — a hint for UX, never the gate.4142## Required Workflow43441. Gather providers, session, and compliance requirements.452. Choose carrier + CSRF strategy against the backend origin layout.463. Plan SSR/middleware integration (Next.js) or SPA boot auth check (Vite).474. Define login/refresh/logout flows and failure UX.485. Record the plan for Gate 2; route enforcement review to `../../security-review`.4950## Decision Rules5152- Default to httpOnly cookie sessions for same-origin apps; bearer tokens make sense mainly when a separate API/multiple clients demand them — then plan storage and refresh explicitly.53- Any secret the browser JS can read is compromised under XSS — design as if XSS happens (`../../security-review`).54- Middleware/route protection is routing UX; every API/server action re-checks identity itself.55- Managed provider vs self-managed is a recorded evaluation, not a default either way.5657## Rules5859- No credentials, tokens, or session secrets in logs, error reports, or public env vars.60- Logout invalidates server-side; a cleared client store alone is not logout.61- Auth pages and redirects must not create open-redirect vectors (validate return paths).6263## Anti-Patterns6465- JWTs in localStorage by habit, with no XSS story.66- Client-side "isLoggedIn" checks guarding data the API serves unauthenticated.67- Refresh logic that fans out (one refresh per parallel 401).68- Rolling custom crypto/session formats instead of vetted mechanisms.6970## Validation Checklist7172- [ ] Provider/model evaluated and chosen with trade-offs.73- [ ] Credential carrier + CSRF strategy defined for the actual origin layout.74- [ ] SSR/middleware (or SPA boot) auth flow planned.75- [ ] Login/refresh/logout lifecycle defined, server-side invalidation included.76- [ ] Client state confirmed as hint-only; server enforcement points listed.7778## Definition of Done7980A recorded authentication plan — provider decision, credential carrier, CSRF posture, SSR integration, and full session lifecycle — where every enforcement point is server-side and the client only reflects it.8182## Related Skills8384`web-authorization`, `web-api-integration`, `web-routing`, `../../security-review`, `../../environment-audit`, `dashboard-permissions`, `nextjs-foundation`.8586## Related Knowledge8788`../../../knowledge/` (identity model, compliance constraints).8990## Related References9192`../../../references/web/` (auth flow notes — when populated).9394## Context Loading Guidance9596- **Requires:** auth requirements, backend/origin layout, framework foundation.97- **Does not require:** UI detail, unrelated feature skills.98- **May load:** `web-authorization` next; `../../security-review` for the enforcement review.99- **Stop when:** the auth plan is recorded for approval.100101## Token Efficiency Guidance102103Decide from the origin/requirements summary. Record the model as carrier + lifecycle + enforcement points; don't restate general auth theory.