feat(auth): implement refresh tokens#355
Open
GTR1701 wants to merge 6 commits into
Open
Conversation
|
Looks like you did not link an issue to this PR. If this PR completes a task, consider linking it. |
There was a problem hiding this comment.
Pull request overview
This PR adds client-side refresh-token handling so API calls can automatically refresh access tokens (or force a logout) based on token expiry state.
Changes:
- Adds refresh-token response typing and new auth utilities for token status evaluation, refresh, and forced logout.
- Updates the fetch execution path to refresh tokens before issuing requests when needed.
- Introduces a client-side “deferred toast” helper and adds a session-expired toast message.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/get-toast-messages.ts | Adds a new auth.sessionExpired toast message string. |
| src/features/toaster/utils/defer-client-toast.ts | New helper to persist a toast in a browser cookie outside React. |
| src/features/toaster/index.ts | Re-exports deferClientToast. |
| src/features/backend/utils/execute-fetch.ts | Adds pre-request token status check + refresh/force-logout logic (client only). |
| src/features/backend/types/responses.ts | Adds RefreshTokenResponse typing for /auth/refresh. |
| src/features/authentication/utils/refresh-access-token.ts | Adds a de-duplicated (singleton) refresh flow to prevent concurrent refresh piling. |
| src/features/authentication/utils/get-token-status.ts | Adds token status evaluation (ok/expiring-soon/expired/both-expired). |
| src/features/authentication/utils/get-cookie-options.ts | Aligns auth cookie expiry with refresh token expiry timestamp. |
| src/features/authentication/utils/force-logout.ts | Adds a client-side forced logout helper that clears auth cookie, defers toast, redirects. |
| src/features/authentication/utils/do-refresh-token.ts | Adds low-level refresh request + cookie persistence of refreshed access token. |
| src/features/authentication/types/internal.ts | Adds TokenStatus type. |
| src/features/authentication/node.ts | Re-exports new auth utilities for non-hook usage. |
| src/features/authentication/constants.ts | Adds REFRESH_THRESHOLD_PERCENT constant for proactive refresh threshold. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
michalges
requested changes
May 24, 2026
Member
|
można się jeszcze zastanowić czy gdy request zawiedzie z kodem 401 to czy nie próbować wtedy refreshować i ponowić request zamiast wylogowywać użytkownika. z tym żeby takie coś zaszło to musiałby być jakiś giga edge case z obecną logiką |
1faef43 to
dffc102
Compare
Comment on lines
+3
to
+7
| export * from "./utils/force-logout"; | ||
| export * from "./utils/get-auth-state.node"; | ||
| export * from "./utils/get-cookie-options"; | ||
| export * from "./utils/get-token-status"; | ||
| export * from "./utils/refresh-access-token"; |
Comment on lines
+7
to
+12
| /** | ||
| * Saves a toast message in a browser cookie to be displayed on the next page render. | ||
| * For use **outside** of React components, where the {@link useSavedToast} hook cannot be used. | ||
| */ | ||
| export const deferClientToast = (toast: SavedToast): void => { | ||
| Cookies.set(SAVED_TOAST_COOKIE_NAME, ...getSavedToastCookieOptions(toast)); |
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.
No description provided.