Skip to content

refactor(provider): return results from every useAuth helper#99

Merged
Bccorb merged 1 commit into
mainfrom
refactor/provider-result-convention
Jul 20, 2026
Merged

refactor(provider): return results from every useAuth helper#99
Bccorb merged 1 commit into
mainfrom
refactor/provider-result-convention

Conversation

@Bccorb

@Bccorb Bccorb commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

What

Unify useAuth() on the same result convention as the headless client. Every provider helper returns SeamlessAuthResult and none of them throw.

Closes #92.

The problem was bigger than the issue described

#92 framed this as one split: client returns results, provider throws. Taking inventory showed useAuth() alone had four styles side by side:

Style Helpers
Throws deleteUser, updateCredential, deleteCredential, switchOrganization, listOAuthProviders, startOAuthLogin, finishOAuthLogin
Returns a result login, verifyStepUpWithPasskey, verifyStepUpWithPasskeyPrf, verifyStepUpWithTotp
Returns a boolean handlePasskeyLogin
Returns a null sentinel refreshStepUpStatus

So there was no rule to learn, only per-method memorization, and #64 would have propagated that to every adapter.

Three silent breakages this could have shipped

The conversion compiles cleanly whether or not callers are updated, because a result object is always truthy. That makes the failure mode silent, and three call sites were affected:

  • Login: if (passkeyResult) was always true, so a failed passkey login would have navigated home as if it succeeded
  • PassKeyLogin: same shape, same outcome
  • OAuthCallback: used .then() / .catch(), and since the helper no longer rejects, .then() ran on failure too and navigated home

All three now check error. Worth flagging because typecheck cannot catch this class, so any adopter doing the same migration should grep their own truthiness checks rather than trusting the compiler.

State updates still gated on success

Helpers that mutate provider state apply the change only when the call succeeds. switchOrganization still refreshes the session, deleteCredential still prunes local state, and logout keeps its finally so local state clears even on a failed sign-out.

Changes

  • src/AuthProvider.tsx: every helper returns a result; AuthContextType updated
  • src/views/{Login,PassKeyLogin,OAuthCallback}.tsx and src/components/OAuthProviderButtons.tsx: consume results
  • README: the "two error styles" section is replaced with "one error style everywhere", and the useAuth() signature block and credential example are updated
  • Tests updated; suite unchanged at 221 passing

Checks

  • npm run typecheck, npm run lint, npm run format:check clean
  • Full suite: 221 passed
  • Changeset (minor) with a per-helper migration list

@Bccorb
Bccorb force-pushed the refactor/provider-result-convention branch from 786a1ca to b2c7f74 Compare July 20, 2026 15:05
@Bccorb
Bccorb merged commit f0c4bd9 into main Jul 20, 2026
2 of 3 checks passed
@Bccorb
Bccorb deleted the refactor/provider-result-convention branch July 20, 2026 15:07
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.

Decide whether provider helpers should throw or return results

1 participant