Skip to content

fix: GET /api/auth/me never returns 401 to avoid Basic Auth credential reset#1067

Merged
perber merged 1 commit into
mainfrom
fix/auth-me-no-401-basic-auth-reset
May 29, 2026
Merged

fix: GET /api/auth/me never returns 401 to avoid Basic Auth credential reset#1067
perber merged 1 commit into
mainfrom
fix/auth-me-no-401-basic-auth-reset

Conversation

@perber
Copy link
Copy Markdown
Owner

@perber perber commented May 29, 2026

Unauthenticated requests to /api/auth/me previously returned 401, causing browsers behind a Basic Auth reverse proxy (e.g. Traefik basicAuth) to discard their cached credentials. Moves the endpoint to an OptionalAuth group that returns 200+null when no session is present. Adds Cache-Control: no-store to prevent reverse proxies from caching the identity response. Preserves the frontend session on 5xx/network errors (only clears on 4xx).

Closes #1013

…l reset

Unauthenticated requests to /api/auth/me previously returned 401, causing
browsers behind a Basic Auth reverse proxy (e.g. Traefik basicAuth) to
discard their cached credentials. Moves the endpoint to an OptionalAuth
group that returns 200+null when no session is present. Adds Cache-Control:
no-store to prevent reverse proxies from caching the identity response.
Preserves the frontend session on 5xx/network errors (only clears on 4xx).

Closes #1013
Copilot AI review requested due to automatic review settings May 29, 2026 14:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts auth bootstrapping so /api/auth/me can be safely called without a session, avoiding browser Basic Auth credential resets while preserving identity freshness and cache safety.

Changes:

  • Adds optional auth handling for /api/auth/me, returning 200 with null for unauthenticated callers.
  • Adds no-store cache headers and backend/e2e coverage for authenticated and unauthenticated /auth/me.
  • Updates frontend auth bootstrap error handling to preserve sessions on server/network failures.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
ui/leafwiki-ui/src/lib/bootstrapAuth.ts Uses typed API errors to clear sessions only on explicit 4xx auth failures.
ui/leafwiki-ui/src/lib/api/auth.ts Allows fetchMe() to return null and propagates status via ApiError.
internal/wiki/wiki.go Defers search indexing status finalization.
internal/wiki/auth/routes.go Moves /auth/me to optional auth and adds no-cache identity response headers.
internal/http/router_test.go Adds router tests for /auth/me null/user responses and cache headers.
internal/http/middleware/auth/current_user.go Adds nullable user lookup helper.
internal/http/middleware/auth/auth.go Adds optional authentication middleware.
e2e/tests/auth.spec.ts Adds Playwright coverage for /auth/me status, body, and cache headers.
internal/http/middleware/auth/auth_test.go Adds middleware tests for optional auth behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ui/leafwiki-ui/src/lib/bootstrapAuth.ts
@perber perber merged commit 5e0f317 into main May 29, 2026
9 checks passed
@perber perber deleted the fix/auth-me-no-401-basic-auth-reset branch May 29, 2026 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

POST /api/auth/refresh-token returning 401 resets browser Basic Auth credentials

2 participants