Skip to content

fix: refresh session on auth check to prevent premature expiration#172

Merged
zhenghaoz merged 1 commit intogorse-io:masterfrom
zhangzhenghao:fix/session-refresh
Apr 27, 2026
Merged

fix: refresh session on auth check to prevent premature expiration#172
zhenghaoz merged 1 commit intogorse-io:masterfrom
zhangzhenghao:fix/session-refresh

Conversation

@zhangzhenghao
Copy link
Copy Markdown
Contributor

Problem

After #166 moved auth check to frontend for CDN-friendly caching, the session.permanent = True was 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 = True to the /api/me endpoint. 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

  • Added session.permanent = True in /api/me when user is authenticated

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.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/me is 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/me returns user-specific auth state (and login) but doesn’t set any anti-caching headers or Vary: Cookie. If a CDN/proxy caches this GET response, it can leak one user’s auth/login to another. Please set Cache-Control to a private/no-store value (consistent with other auth-sensitive endpoints) and add Vary: Cookie on 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.

@zhenghaoz zhenghaoz merged commit a3a7841 into gorse-io:master Apr 27, 2026
5 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.

3 participants