Skip to content

fix(clerk_auth): authenticate delete requests and preserve failed deletions - #450

Open
funkydevil wants to merge 2 commits into
clerk-community:mainfrom
funkydevil:codex/fix-delete-user
Open

fix(clerk_auth): authenticate delete requests and preserve failed deletions#450
funkydevil wants to merge 2 commits into
clerk-community:mainfrom
funkydevil:codex/fix-delete-user

Conversation

@funkydevil

Copy link
Copy Markdown

Summary

  • authenticate both DELETE /client and DELETE /me before clearing cached credentials
  • keep local sign-out behavior when the network request fails
  • preserve the authenticated session when account deletion fails
  • surface failed account deletion instead of returning Client.empty
  • clear the persisted client only after successful account deletion

Problem

_delete cleared TokenCache before building the request. As a result, the
Authorization header and _clerk_session_id query parameter were missing
from DELETE /me. Clerk could return a response without deleting the user,
while the SDK replaced its local client with an empty client and reported
success.

Moving the cache clear into an unconditional finally, as proposed in #446,
correctly authenticates the request and preserves offline sign-out behavior.
However, account deletion has different failure semantics: if DELETE /me
fails, clearing the cache turns that failure into a local sign-out and the
caller can still believe that the account was deleted.

This change lets _delete distinguish the two operations:

  • signOut() always clears local credentials after attempting the request.
  • deleteUser() retains credentials on failure, throws an ExternalError,
    and clears them only after a successful response.

Tests

  • verifies that sign-out sends the client token and then clears it
  • verifies that user deletion sends both the client token and session ID
  • verifies that successful deletion clears credentials
  • verifies that failed deletion throws and preserves the signed-in user
  • preserves the existing offline sign-out tests

Local verification:

  • dart analyze
  • dart test — 674 passed, 1 skipped because it requires a configured Web3 wallet

Related to #446.

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.

2 participants