Skip to content

Auto-retry the original mutation after re-authenticating from the SIWE 401 banner #327

Description

@Lakes41

Difficulty: Intermediate
Type: bug

Background
The README documents that "401 from backend shows inline re-auth banner without page redirect" as step 8 of the SIWE sign-in flow, implying admins can re-authenticate in place after a session expires.

Problem
After an admin re-authenticates via the inline banner, the mutation that originally triggered the 401 (e.g., a role assignment or policy update) is likely lost, forcing the admin to manually redo the action instead of it completing automatically once a valid session is restored.

Expected outcome
When a mutation fails with 401 (via AuthError from lib/api/live.ts), the UI shows the re-auth banner, and upon successful re-authentication, the original mutation is automatically retried with the new token — with a clear success/failure toast either way.

Suggested implementation

  • Extend the AuthError handling path in lib/api/live.ts (or the calling hook) to capture the failed request's parameters before surfacing the re-auth banner.
  • After useSiweAuth() completes a successful re-auth, replay the captured request using the new token.
  • Ensure only one retry attempt occurs (avoid infinite loops if the retried request also 401s).
  • Add a toast/notification confirming whether the retried mutation succeeded.

Acceptance criteria

  • A 401 during a mutation triggers the existing inline re-auth banner
  • Successful re-auth automatically retries the original mutation exactly once
  • A second 401 after retry shows a clear failure message rather than looping
  • Verified for at least role assignment and policy update mutations

Likely affected files/directories

  • lib/api/live.ts
  • lib/wallet/providers.tsx (SiweAuthContext)
  • components/admin-guard.tsx

Metadata

Metadata

Assignees

Labels

GrantFox OSSGrantFox Open Source Sponsorship program tagMaybe RewardedIssue may qualify for a reward upon successful completion per campaign rulesOfficial Campaign | FWC26Official FWC26 campaign issue — eligible for campaign scoring and rewardsbugConfirmed defect or incorrect behavior that needs to be fixedintermediateIntermediate difficulty tasks requiring solid experience and some context

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions