Skip to content

fix: auto-retry mutation after SIWE re-auth on 401 - #365

Merged
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
OlaGreat:fix/retry-mutation-after-reauth
Jul 28, 2026
Merged

fix: auto-retry mutation after SIWE re-auth on 401#365
Lakes41 merged 1 commit into
Adamantine-guild:mainfrom
OlaGreat:fix/retry-mutation-after-reauth

Conversation

@OlaGreat

Copy link
Copy Markdown
Contributor

When a mutation (role assignment, policy update) fails with a 401 AuthError, the original request is now automatically retried once after the user successfully re-authenticates via the inline banner.

Changes:

  • lib/wallet/siwe-context.ts: add PendingRetryCallback type and registerPendingRetry to SiweAuthContextType
  • lib/wallet/providers.tsx: implement pendingRetriesRef queue; drain it in both signIn() and performSilentRefresh() after a successful session recovery; add registerPendingRetry to context value and SiweAuthContextValue interface
  • admin/members/page.tsx: use registerPendingRetry in assignRole and removeRole onError handlers; remove React Query built-in retry for 401s to avoid racing with the re-auth banner flow
  • admin/policies/page.tsx: use registerPendingRetry in policy mutation onError; add useToasts/ToastViewport for retry feedback
  • test mocks: add registerPendingRetry: () => {} to all three useSiweAuth mock objects

Acceptance criteria met:

  • 401 during mutation triggers inline re-auth banner
  • Successful re-auth automatically retries original mutation once
  • Second 401 on retry calls onRetryFailure (no infinite loop)
  • Success/failure toasts shown for the retried mutation

Closes #327

When a mutation (role assignment, policy update) fails with a 401
AuthError, the original request is now automatically retried once
after the user successfully re-authenticates via the inline banner.

Changes:
- lib/wallet/siwe-context.ts: add PendingRetryCallback type and
  registerPendingRetry to SiweAuthContextType
- lib/wallet/providers.tsx: implement pendingRetriesRef queue;
  drain it in both signIn() and performSilentRefresh() after a
  successful session recovery; add registerPendingRetry to context
  value and SiweAuthContextValue interface
- admin/members/page.tsx: use registerPendingRetry in assignRole
  and removeRole onError handlers; remove React Query built-in
  retry for 401s to avoid racing with the re-auth banner flow
- admin/policies/page.tsx: use registerPendingRetry in policy
  mutation onError; add useToasts/ToastViewport for retry feedback
- test mocks: add registerPendingRetry: () => {} to all three
  useSiweAuth mock objects

Acceptance criteria met:
- 401 during mutation triggers inline re-auth banner
- Successful re-auth automatically retries original mutation once
- Second 401 on retry calls onRetryFailure (no infinite loop)
- Success/failure toasts shown for the retried mutation
@Lakes41
Lakes41 merged commit 252faf7 into Adamantine-guild:main Jul 28, 2026
1 check passed
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.

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

2 participants