fix: GET /api/auth/me never returns 401 to avoid Basic Auth credential reset#1067
Merged
Conversation
…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
Contributor
There was a problem hiding this comment.
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, returning200withnullfor 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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