Skip to content

Fix SIWE Provider Type Imports and Unauthorised Invalidation Flow #55

Description

@Lakes41

Difficulty: Hard

Type: Bug

Summary

Fix the SIWE auth provider so TypeScript builds reliably and unauthorised API responses consistently reset the admin session.

Current Behaviour

lib/wallet/providers.tsx uses AdminSessionStatus but only imports SiweAuthSession from the API types. The provider also defines an unauthorised error handling path inside React Query configuration, but the invalidation event flow is incomplete and may not actually clear cached session state when an API call returns 401.

Expected Behaviour

The SIWE provider should typecheck cleanly and any unauthorised API response should clear the stored token, reset admin auth state, and invalidate related React Query cache entries.

Suggested Implementation

Import AdminSessionStatus from lib/api/types.ts. Replace the current query-level unauthorised handling with a supported React Query v5 pattern, such as a QueryCache or MutationCache onError handler on the QueryClient. When an ApiError has code === 'unauthorized', clear the SIWE session, dispatch or directly call the invalidation flow, and remove session and access decision queries.

Files or Areas Likely Affected

  • lib/wallet/providers.tsx
  • lib/api/errors.ts
  • lib/query/
  • test/*.test.ts

Acceptance Criteria

  • npm run typecheck passes without missing type imports.
  • A 401 API error clears the stored SIWE auth session.
  • Session and access-decision React Query caches are removed after unauthorised errors.
  • Admin pages return to the re-authentication state after session expiry.
  • Tests cover unauthorised error handling and session invalidation.

Additional Notes

This should stay aligned with React Query v5 APIs. Avoid relying on unsupported query option callbacks that may not fire or may fail typechecking.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official Campaign

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions