Move auth check to frontend for CDN-friendly caching#166
Merged
zhenghaoz merged 3 commits intogorse-io:masterfrom Apr 26, 2026
Merged
Move auth check to frontend for CDN-friendly caching#166zhenghaoz merged 3 commits intogorse-io:masterfrom
zhenghaoz merged 3 commits intogorse-io:masterfrom
Conversation
06ef582 to
4587f2b
Compare
- Backend: Remove login checks from page routes (/ /login /privacy /404) - Backend: Add /api/me endpoint for frontend auth status check - Backend: Add Cache-Control headers to disable CDN caching on API endpoints - Frontend: Add router guard to check authentication before accessing protected routes This change makes all page routes return static files that can be safely cached by CDN, while authentication logic is handled by the frontend.
- Add localStorage cache for auth state with 5-minute expiry - Add axios interceptor to handle 401 errors globally - Clear cache and redirect to login on auth failure - Reduce unnecessary /api/me requests
5f1450d to
fd26a88
Compare
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.
Summary
/,/login,/privacy,404) - all routes now directly return staticindex.html/api/meendpoint for frontend to check authentication statusCache-Control: private, no-store, no-cache, must-revalidateheaders to all/api/*endpoints to prevent CDN cachingbeforeEach) to check auth via/api/mebefore allowing access to protected routesBenefits
Changes
Backend (app.py)
@login_requiredand redirect logic from/,/login,/privacy, andpage_not_found/api/meendpoint returning{is_authenticated: true/false, login: string}Cache-Controlheader inset_headers()for all/api/*pathsFrontend (frontend/src/main.js)
meta: { requiresAuth: true }to protected routesrouter.beforeEachguard that calls/api/meand redirects to/loginif not authenticatedTesting
Tested locally:
/loginwhen accessing/or/favorites/api/mereturns correct authentication status