fix: #652 bugfix session silently timing out - #1045
Merged
Merged
Conversation
craigyu
requested review from
Abradat,
carolinemwood and
paulushcgcj
as code owners
November 4, 2025 16:48
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors authentication and token management from AWS Amplify's cookie-based storage to a cookie-based approach managed by the application. It introduces automatic token refresh handling via TanStack Query's error handling mechanism and adds security hardening to the backend XML processing.
- Introduces
CookieUtilsfor managing authentication tokens via cookies instead of relying on Amplify's internal storage - Implements token refresh logic in
tanstackConfigwith automatic retry of failed queries/mutations on 401 errors - Adds XXE (XML External Entity) protection to
TransformerFactoryinstances in backend XML processing
Reviewed Changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
frontend/src/utils/CookieUtils.ts |
New utility module for cookie management (set, get, delete) |
frontend/src/services/API.ts |
Updates OpenAPI token provider to read from cookies instead of AuthService |
frontend/src/contexts/AuthProvider.tsx |
Refactored to use cookie storage and simplified session handling without polling |
frontend/src/constants/tanstackConfig.ts |
Major expansion adding token refresh logic, error handlers, and automatic retry on 401 |
frontend/src/constants/index.ts |
Added ACCESS_TOKEN_KEY constant |
frontend/src/__test__/index.test.tsx |
Added mocks for QueryCache and MutationCache |
frontend/src/__test__/contexts/PreferenceProvider.test.tsx |
Minor formatting change to empty function |
frontend/src/__test__/contexts/AuthProvider.test.tsx |
Updated test mocks to simulate cookie-based token retrieval |
frontend/package-lock.json |
Removed peer: true markers from various dependencies |
backend/src/test/java/.../OpeningSpatialFileServiceTest.java |
Removed unused throws Exception from test method |
backend/src/main/java/.../OpeningSpatialFileService.java |
Added XXE protection to TransformerFactory, pattern matching improvement, and formatting |
Files not reviewed (1)
- frontend/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)
frontend/src/constants/tanstackConfig.ts:21
- The value assigned to API_BASE_URL here is unused.
API_BASE_URL = API_BASE_URL.slice(0, -4);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Abradat
approved these changes
Nov 4, 2025
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.
Description
Switch token refresh from periodic polling to on-demand refresh: refresh the Amplify session only when a request fails with 401, refresh the access token via Amplify, then retry the failed queries — avoiding client-side refresh tokens and eliminating the polling interval.
Previously the app polled Amplify on a timer to refresh tokens. Now the app refreshes the session only when a request fails due to an expired/invalid access token (HTTP 401). The refresh is handled by Amplify's session APIs; after a successful refresh we set the access token cookie for the API client and automatically retry queued queries/mutations. This reduces unnecessary network calls, centralizes refresh logic, and avoids storing refresh tokens in JS-accessible storage.
Summary
Note
This PR include a maintainability update to the backend, the commit was missed from my last PR.
Thanks for the PR!
Deployments, as required, will be available below:
Please create PRs in draft mode. Mark as ready to enable:
After merge, new images are deployed in:
Thanks for the PR!
Deployments, as required, will be available below:
Please create PRs in draft mode. Mark as ready to enable:
After merge, new images are deployed in: