Make auth work from a Capacitor WebView origin (JWT-only, CORS/CSRF for capacitor://localhost) #22
Notifications
Due Date
No due date set.
Blocks
#20 Ship Android app by wrapping the web build with Capacitor
ai_ml_operations/chat_web_app
#21 Ship iOS app by wrapping the web build with Capacitor
ai_ml_operations/chat_web_app
Reference: ai_ml_operations/chat_web_app#22
Reference in New Issue
Block a user
Risk
Blocks #20 (Android) and #21 (iOS).
Today
llm-fe/src/axiosApi.jsauthenticates with a JWT plus a CSRF cookie read viajs-cookie. In a browser the app and API are same-site-ish (chat.aimloperations.com->chatbackend.aimloperations.com), so the cookie flow works. Inside Capacitor the page origin ishttps://localhost(Android) orcapacitor://localhost(iOS), which is cross-site relative to the backend domain, and WKWebView blocks third-party cookies by default. Result: the CSRF cookie is never readable, POSTs get rejected, and login fails on device even though the same bundle works in a browser.Work
src/axiosApi.jsand the auth context for every request that depends on a cookie (CSRF token, session, refresh token).Authorizationbearer JWT, refresh token in Capacitor Preferences / secure storage rather than a cookie.chat_backendchanges: addhttps://localhostandcapacitor://localhosttoCORS_ALLOWED_ORIGINSandCSRF_TRUSTED_ORIGINS; verify preflight (OPTIONS) responses andAccess-Control-Allow-Credentialsbehavior.Done when
Login, refresh, and an authenticated API call all succeed from a Capacitor build on both platforms, with no cookie dependency, and the browser build still works unchanged.
westfarn referenced this issue2026-08-03 12:13:08 -07:00