Handling "Account Already Linked" Error in React Native with Social Account Linking #1655

Closed
opened 2026-03-13 08:53:58 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @quuentinho on GitHub (Aug 7, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

export const useLinkGoogleAccount = () => {
    return useSyncMutation({
        mutationFn: async () => {
            const result = await authClient.linkSocial({
                provider: "google",
                callbackURL: "myapp://settings"
            })
            return result
        },
        onSuccess: async (response) => {
            // How to detect if Google account is already linked to another user?
            if (response?.error) {
                const errorCode = response.error.code || ""
                
                // This doesn't seem to work for "already linked" errors
                if (errorCode === "ACCOUNT_ALREADY_LINKED") {
                    // Show user-friendly message
                    return
                }
            }
            
            // Success case
            await Linking.openURL(response.data.url)
        }
    })
}

Current vs. Expected behavior

Current Behavior

  1. User calls authClient.linkSocial({ provider: "google", callbackURL: "myapp://settings" })
  2. User is redirected to Google OAuth flow
  3. If the Google account is already linked to another user account, the OAuth flow completes but the user is redirected back to the app without clear error information
  4. The linkSocial() response doesn't contain error details about the conflict

Expected Behavior

When a social account is already linked to a different user, there should be a clear way to:

  1. Detect this error condition in the client
  2. Show appropriate user feedback
  3. Handle the error gracefully without leaving the user confused

What version of Better Auth are you using?

1.2.10

Provide environment information

## Environment

- Better Auth version: 1.2.10
- Platform: React Native + Expo SDK 53
- Social provider: Google

Which area(s) are affected? (Select all that apply)

Client

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

Currently testing shows that when a Google account is already linked to another user, the OAuth flow redirects back to the app but without clear error indication, making it difficult to provide proper user feedback.

Any guidance on the proper error handling pattern would be greatly appreciated!

Originally created by @quuentinho on GitHub (Aug 7, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ```javascript export const useLinkGoogleAccount = () => { return useSyncMutation({ mutationFn: async () => { const result = await authClient.linkSocial({ provider: "google", callbackURL: "myapp://settings" }) return result }, onSuccess: async (response) => { // How to detect if Google account is already linked to another user? if (response?.error) { const errorCode = response.error.code || "" // This doesn't seem to work for "already linked" errors if (errorCode === "ACCOUNT_ALREADY_LINKED") { // Show user-friendly message return } } // Success case await Linking.openURL(response.data.url) } }) } ``` ### Current vs. Expected behavior ## Current Behavior 1. User calls `authClient.linkSocial({ provider: "google", callbackURL: "myapp://settings" })` 2. User is redirected to Google OAuth flow 3. If the Google account is already linked to another user account, the OAuth flow completes but the user is redirected back to the app without clear error information 4. The `linkSocial()` response doesn't contain error details about the conflict ## Expected Behavior When a social account is already linked to a different user, there should be a clear way to: 1. Detect this error condition in the client 2. Show appropriate user feedback 3. Handle the error gracefully without leaving the user confused ### What version of Better Auth are you using? 1.2.10 ### Provide environment information ```bash ## Environment - Better Auth version: 1.2.10 - Platform: React Native + Expo SDK 53 - Social provider: Google ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context Currently testing shows that when a Google account is already linked to another user, the OAuth flow redirects back to the app but without clear error indication, making it difficult to provide proper user feedback. Any guidance on the proper error handling pattern would be greatly appreciated!
GiteaMirror added the social-providerexpo labels 2026-03-13 08:53:58 -05:00
Author
Owner

@quuentinho commented on GitHub (Aug 11, 2025):

Is anyone else experiencing the same issue?

@quuentinho commented on GitHub (Aug 11, 2025): Is anyone else experiencing the same issue?
Author
Owner

@frectonz commented on GitHub (Aug 13, 2025):

SOCIAL_ACCOUNT_ALREADY_LINKED is no longer being returned as an error. It is no longer considered an error is the linking failing for you or do you just want the SOCIAL_ACCOUNT_ALREADY_LINKED to be returned as an error.

@frectonz commented on GitHub (Aug 13, 2025): `SOCIAL_ACCOUNT_ALREADY_LINKED` is no longer being returned as an error. It is no longer considered an error is the linking failing for you or do you just want the `SOCIAL_ACCOUNT_ALREADY_LINKED` to be returned as an error.
Author
Owner

@quuentinho commented on GitHub (Sep 4, 2025):

@frectonz I would like this specific scenario (SOCIAL_ACCOUNT_ALREADY_LINKED) to be returned as an error so I can show appropriate feedback to the user. When a user tries to link a Google account that's already linked to another account, I need to be able to detect this situation and display a clear error message like 'This Google account is already linked to another user'.

@quuentinho commented on GitHub (Sep 4, 2025): @frectonz I would like this specific scenario (SOCIAL_ACCOUNT_ALREADY_LINKED) to be returned as an error so I can show appropriate feedback to the user. When a user tries to link a Google account that's already linked to another account, I need to be able to detect this situation and display a clear error message like 'This Google account is already linked to another user'.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1655