fix: add missing error tracking for BetterAuth flows#5768
Merged
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
rebelchris
approved these changes
Mar 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
auth_strategyA/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
useLogin.tsonSubmitSocialLoginbetterAuthSignInWithIdTokenreturns error → no event loggeduseLogin.tsonSubmitSocialLogingetBetterAuthSocialUrlreturns null → no event loggeduseRegistration.tsbetterAuthRegister.onSuccessres.error→ callsonInvalidRegistrationbut no analytics eventuseRegistration.tsbetterAuthRegister.onSuccessres.status && !res.userfallback → no analytics eventuseRegistration.tsonSocialRegistrationbetterAuthSignInWithIdTokenreturns error → no event loggeduseRegistration.tsonSocialRegistrationgetBetterAuthSocialUrlreturns null → no event loggedAuthOptionsInner.tsxbetterAuthSignInWithIdTokenreturns error → no event loggedAuthOptionsInner.tsxgetBetterAuthSocialUrlreturns null → no event loggedImpact 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: Loglogin errorevent onbetterAuthSignInWithIdTokenfailure andgetBetterAuthSocialUrlfailure. Also removed redundantif (socialUrl)check after early return.useRegistration.ts: Logregistration errorevent onbetterAuthSignUperror response, fallback error,betterAuthSignInWithIdTokenfailure, andgetBetterAuthSocialUrlfailure.AuthOptionsInner.tsx: Loglogin errorevent onbetterAuthSignInWithIdTokenfailure andgetBetterAuthSocialUrlfailure.All events use the existing
AuthEventNames(login error/registration error) so they flow into the existing GrowthBook metrics. Each event includes anoriginfield prefixed withbetterauthfor easy filtering:betterauth native id tokenbetterauth social urlbetterauth signup errorbetterauth signup fallback errorbetterauth native id token registrationbetterauth social url registrationTesting
login errorevent fires on failureregistration errorevent fires on failurebetterauthorigin events after deployPreview domain
https://fix-better-auth-error-tracking.preview.app.daily.dev