fix(auth): refresh before token expiry#1042
Merged
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
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
accessTokenExpiresAtin login and refresh JSON responses (derived from the JWTexp). - Frontend: persist
accessTokenExpiresAtin the session store and refresh before requests when within a threshold of expiry. - Tests: assert that login/refresh responses include a future
accessTokenExpiresAttimestamp.
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.
Document the access token expiry unit in the session store and avoid redundant session clearing after logout-backed cleanup.
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.
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.