Skip to content

Comments

Fix CORS headers missing on error responses in desktop app#272

Merged
Mng-dev-ai merged 2 commits intomainfrom
fix/desktop-cors-refresh-token
Feb 22, 2026
Merged

Fix CORS headers missing on error responses in desktop app#272
Mng-dev-ai merged 2 commits intomainfrom
fix/desktop-cors-refresh-token

Conversation

@Mng-dev-ai
Copy link
Owner

Summary

  • Reorder middleware so CORSMiddleware is the outermost (last added), ensuring CORS headers are present on all responses including 500s from inner middleware
  • Previously, error responses from RequestIdMiddleware or SecurityHeadersMiddleware bypassed CORSMiddleware, causing WebKit in Tauri to block the response entirely — the frontend couldn't read the status code to handle auth failures
  • Simplify shouldInvalidateSession from multiple early returns to a single expression

Test plan

  • Launch desktop app with a stale/expired refresh token in localStorage
  • Verify the app redirects to login instead of getting stuck in a retry loop
  • Verify normal auth flow (login, token refresh, logout) still works in both web and desktop

Move CORSMiddleware to be the outermost middleware so CORS headers are
always present — even on 500s from inner middleware. Previously, error
responses bypassed CORS, causing WebKit to block them entirely and
preventing the frontend from reading the status code to invalidate
stale sessions.

Also simplify shouldInvalidateSession to a single expression.
Only invalidate the session when the refresh endpoint returns 401
(token is genuinely invalid). Other 4xx like 429 (rate limited) or
422 (validation error) are transient and shouldn't log the user out.
@Mng-dev-ai Mng-dev-ai merged commit 36ea27d into main Feb 22, 2026
3 of 4 checks passed
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.

1 participant