Skip to content

fix: #652 bugfix session silently timing out - #1045

Merged
craigyu merged 14 commits into
mainfrom
fix/652-bugfix-session-silently-timing-out
Nov 6, 2025
Merged

fix: #652 bugfix session silently timing out#1045
craigyu merged 14 commits into
mainfrom
fix/652-bugfix-session-silently-timing-out

Conversation

@craigyu

@craigyu craigyu commented Nov 4, 2025

Copy link
Copy Markdown
Collaborator

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

  • Token refresh is triggered on-demand when a 401 occurs (not on a timer).
  • While refresh occurs, failed queries are marked as loading/fetching to avoid UI error states.
  • After refresh succeeds, the queued queries/mutations are retried automatically.

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:

@craigyu craigyu self-assigned this Nov 4, 2025
@craigyu craigyu linked an issue Nov 4, 2025 that may be closed by this pull request
@Abradat
Abradat requested a review from Copilot November 4, 2025 17:27

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 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 CookieUtils for managing authentication tokens via cookies instead of relying on Amplify's internal storage
  • Implements token refresh logic in tanstackConfig with automatic retry of failed queries/mutations on 401 errors
  • Adds XXE (XML External Entity) protection to TransformerFactory instances 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.

Comment thread frontend/src/utils/CookieUtils.ts Outdated
Comment thread frontend/src/utils/CookieUtils.ts
Comment thread frontend/src/constants/tanstackConfig.ts Outdated
Comment thread frontend/src/constants/tanstackConfig.ts Outdated
Comment thread frontend/src/constants/tanstackConfig.ts Outdated
craigyu and others added 5 commits November 4, 2025 09:32
@craigyu
craigyu enabled auto-merge (squash) November 6, 2025 18:27
@craigyu
craigyu merged commit f000e19 into main Nov 6, 2025
24 of 26 checks passed
@craigyu
craigyu deleted the fix/652-bugfix-session-silently-timing-out branch November 6, 2025 18:32
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.

[BUGFIX]: Session silently timing out

3 participants