Skip to content

fix: add missing error tracking for BetterAuth flows#5768

Merged
idoshamun merged 3 commits intomainfrom
fix/better-auth-error-tracking
Mar 22, 2026
Merged

fix: add missing error tracking for BetterAuth flows#5768
idoshamun merged 3 commits intomainfrom
fix/better-auth-error-tracking

Conversation

@idoshamun
Copy link
Member

@idoshamun idoshamun commented Mar 22, 2026

Problem

The auth_strategy A/B experiment shows error rates down but signups also down in the BetterAuth (treatment) variation. Investigation revealed that BetterAuth code paths silently swallow errors without logging analytics events — the errors are not actually gone, they are just invisible.

Silent failure paths found

File Function What fails silently
useLogin.ts onSubmitSocialLogin betterAuthSignInWithIdToken returns error → no event logged
useLogin.ts onSubmitSocialLogin getBetterAuthSocialUrl returns null → no event logged
useRegistration.ts betterAuthRegister.onSuccess res.error → calls onInvalidRegistration but no analytics event
useRegistration.ts betterAuthRegister.onSuccess res.status && !res.user fallback → no analytics event
useRegistration.ts onSocialRegistration betterAuthSignInWithIdToken returns error → no event logged
useRegistration.ts onSocialRegistration getBetterAuthSocialUrl returns null → no event logged
AuthOptionsInner.tsx social login handler betterAuthSignInWithIdToken returns error → no event logged
AuthOptionsInner.tsx social login handler getBetterAuthSocialUrl returns null → no event logged

Impact on experiment

The Kratos (control) path logs errors at every failure point. BetterAuth paths return early without logging, making the error rate metric artificially low. Meanwhile, users are silently dropping off, explaining the signup/login success drop.

Changes

  • useLogin.ts: Log login error event on betterAuthSignInWithIdToken failure and getBetterAuthSocialUrl failure. Also removed redundant if (socialUrl) check after early return.
  • useRegistration.ts: Log registration error event on betterAuthSignUp error response, fallback error, betterAuthSignInWithIdToken failure, and getBetterAuthSocialUrl failure.
  • AuthOptionsInner.tsx: Log login error event on betterAuthSignInWithIdToken failure and getBetterAuthSocialUrl failure.

All events use the existing AuthEventNames (login error / registration error) so they flow into the existing GrowthBook metrics. Each event includes an origin field prefixed with betterauth for easy filtering:

  • betterauth native id token
  • betterauth social url
  • betterauth signup error
  • betterauth signup fallback error
  • betterauth native id token registration
  • betterauth social url registration

Testing

  • Trigger social login with BetterAuth enabled → verify login error event fires on failure
  • Trigger email signup with BetterAuth enabled → verify registration error event fires on failure
  • Verify existing Kratos paths still log events as before (no changes to those paths)
  • Check analytics events table for new betterauth origin events after deploy

Preview domain

https://fix-better-auth-error-tracking.preview.app.daily.dev

BetterAuth paths silently swallow errors without logging analytics events,
making auth error metrics unreliable during the auth_strategy experiment.

Changes:
- useLogin: log LoginError on betterAuthSignInWithIdToken failure and
  getBetterAuthSocialUrl failure (native + web social login)
- useRegistration: log RegistrationError on betterAuthSignUp error,
  fallback error, betterAuthSignInWithIdToken failure, and
  getBetterAuthSocialUrl failure (native + web social registration)
- AuthOptionsInner: log LoginError on betterAuthSignInWithIdToken failure
  and getBetterAuthSocialUrl failure

All events use existing AuthEventNames (login error / registration error)
with a new origin field prefixed betterauth for easy filtering.
@vercel
Copy link

vercel bot commented Mar 22, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
daily-webapp Ready Ready Preview Mar 22, 2026 8:52am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
storybook Ignored Ignored Mar 22, 2026 8:52am

Request Review

@idoshamun idoshamun marked this pull request as ready for review March 22, 2026 08:29
@idoshamun idoshamun merged commit 9a4bf7a into main Mar 22, 2026
13 checks passed
@idoshamun idoshamun deleted the fix/better-auth-error-tracking branch March 22, 2026 08:29
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