Skip to content

fix(auth): refresh before token expiry#1042

Merged
perber merged 2 commits into
mainfrom
fix/proactive-token-refresh
May 25, 2026
Merged

fix(auth): refresh before token expiry#1042
perber merged 2 commits into
mainfrom
fix/proactive-token-refresh

Conversation

@perber

@perber perber commented May 25, 2026

Copy link
Copy Markdown
Owner

Return access token expiry metadata from login and refresh responses so the frontend can refresh proactively before protected requests.

This reduces visible 401 responses for expiring sessions while keeping the existing refresh-on-401 fallback in place.

Return access token expiry metadata from login and refresh responses so the frontend can refresh proactively before protected requests.

This reduces visible 401 responses for expiring sessions while keeping the existing refresh-on-401 fallback in place.
Copilot AI review requested due to automatic review settings May 25, 2026 13:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds access token expiry metadata to the auth API (login + refresh) and uses it in the UI to proactively refresh sessions shortly before expiry, reducing user-visible 401s while keeping the existing refresh-on-401 fallback.

Changes:

  • Backend: include accessTokenExpiresAt in login and refresh JSON responses (derived from the JWT exp).
  • Frontend: persist accessTokenExpiresAt in the session store and refresh before requests when within a threshold of expiry.
  • Tests: assert that login/refresh responses include a future accessTokenExpiresAt timestamp.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ui/leafwiki-ui/src/stores/session.ts Persist access token expiry metadata alongside the user in the session store.
ui/leafwiki-ui/src/lib/api/auth.ts Store expiry on login/refresh and proactively refresh before protected requests near expiry.
internal/wiki/auth/routes.go Return accessTokenExpiresAt in login and refresh API responses.
internal/http/router_test.go Validate accessTokenExpiresAt is present and in the future for login/refresh responses.
internal/core/auth/auth_service.go Compute and expose access token expiry at token generation time.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ui/leafwiki-ui/src/stores/session.ts Outdated
Comment thread ui/leafwiki-ui/src/lib/api/auth.ts Outdated
Document the access token expiry unit in the session store and avoid redundant session clearing after logout-backed cleanup.
@perber
perber merged commit 9cc6ee6 into main May 25, 2026
8 checks passed
@perber
perber deleted the fix/proactive-token-refresh branch May 25, 2026 13:44
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.

2 participants