fix: refresh session on auth check to prevent premature expiration#172
Merged
zhenghaoz merged 1 commit intogorse-io:masterfrom Apr 27, 2026
Merged
Conversation
After moving auth check to frontend, session.permanent was removed from the index route. This caused sessions to expire based on default timeout without being refreshed. Now /api/me refreshes the session on each auth check, matching the previous behavior.
There was a problem hiding this comment.
Pull request overview
Refreshes authenticated user sessions during the frontend auth check flow (/api/me) to prevent premature logout after auth checks were moved client-side for CDN-friendly caching.
Changes:
- Marks the session as permanent when
/api/meis called by an authenticated user (intended to refresh/extend session lifetime during periodic auth checks).
Comments suppressed due to low confidence (1)
app.py:284
/api/mereturns user-specific auth state (and login) but doesn’t set any anti-caching headers orVary: Cookie. If a CDN/proxy caches this GET response, it can leak one user’s auth/login to another. Please setCache-Controlto a private/no-store value (consistent with other auth-sensitive endpoints) and addVary: Cookieon both the authenticated and unauthenticated responses.
if current_user.is_authenticated:
session.permanent = True # Refresh session on auth check
return Response(
json.dumps({"is_authenticated": True, "login": current_user.login}),
mimetype="application/json"
)
💡 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.
Problem
After #166 moved auth check to frontend for CDN-friendly caching, the
session.permanent = Truewas removed from the index route. This caused sessions to expire based on default timeout without being refreshed.Users reported that login state expires very quickly, requiring frequent re-authentication.
Solution
Add
session.permanent = Trueto the/api/meendpoint. This ensures the session is refreshed each time the frontend checks authentication status, matching the previous behavior where session was refreshed on every page load.Changes
session.permanent = Truein/api/mewhen user is authenticated