[GH-ISSUE #544] Social Sign-In Error Handling Failure #25638

Closed
opened 2026-04-17 15:53:35 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @kylegrahammatzen on GitHub (Nov 15, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/544

Describe the bug
When using the authClient.signIn.social() method, the error handling is not working as expected. Specifically, when a provider is not found, the code doesn't throw an error and instead reports a successful sign-in, which is incorrect and potentially misleading.

To Reproduce
Steps to reproduce the behavior:

  1. Implement the following code in your authentication flow:
const { data, error } = await authClient.signIn.social({ provider });

if (error) {
  toast({
    title: "Sign in failed",
    description: `There was an error signing in with ${provider}. Please try again.`,
    variant: "destructive",
  });
}

toast({
  title: "Sign in successful",
  description: `You've successfully signed in with ${provider}.`,
});
  1. Attempt to sign in with a provider that is not configured or doesn't exist.
  2. See that no error is thrown, and a "Sign in successful" toast is displayed.

Expected behavior
When a provider is not found or not properly configured, the code should:

  1. Set the error variable in the returned object.
  2. Trigger the error handling code block.
  3. Display a "Sign in failed" toast with an appropriate error message.

Actual behavior
Currently, when a provider is not found:

  1. No error is set in the returned object.
  2. The error handling code block is skipped.
  3. A "Sign in successful" toast is displayed, which is incorrect.

Console output
The following error is logged to the console, but not captured by the code:
[Better Auth] ERROR Provider not found. Make sure to add the provider in your auth config { provider: 'google' }

Additional context
While this issue may not occur in production with properly configured providers, it's important to handle this scenario for development and testing purposes.

Proposed solution
The authClient.signIn.social() method should be updated to properly set the error object when a provider is not found or improperly configured. This would allow the existing error handling code to catch and display the appropriate error message.

Originally created by @kylegrahammatzen on GitHub (Nov 15, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/544 **Describe the bug** When using the `authClient.signIn.social()` method, the error handling is not working as expected. Specifically, when a provider is not found, the code doesn't throw an error and instead reports a successful sign-in, which is incorrect and potentially misleading. **To Reproduce** Steps to reproduce the behavior: 1. Implement the following code in your authentication flow: ```typescript const { data, error } = await authClient.signIn.social({ provider }); if (error) { toast({ title: "Sign in failed", description: `There was an error signing in with ${provider}. Please try again.`, variant: "destructive", }); } toast({ title: "Sign in successful", description: `You've successfully signed in with ${provider}.`, }); ``` 2. Attempt to sign in with a provider that is not configured or doesn't exist. 3. See that no error is thrown, and a "Sign in successful" toast is displayed. **Expected behavior** When a provider is not found or not properly configured, the code should: 1. Set the `error` variable in the returned object. 2. Trigger the error handling code block. 3. Display a "Sign in failed" toast with an appropriate error message. **Actual behavior** Currently, when a provider is not found: 1. No error is set in the returned object. 2. The error handling code block is skipped. 3. A "Sign in successful" toast is displayed, which is incorrect. **Console output** The following error is logged to the console, but not captured by the code: `[Better Auth] ERROR Provider not found. Make sure to add the provider in your auth config { provider: 'google' }` **Additional context** While this issue may not occur in production with properly configured providers, it's important to handle this scenario for development and testing purposes. **Proposed solution** The `authClient.signIn.social()` method should be updated to properly set the `error` object when a provider is not found or improperly configured. This would allow the existing error handling code to catch and display the appropriate error message.
GiteaMirror added the locked label 2026-04-17 15:53:35 -05:00
Author
Owner

@kylegrahammatzen commented on GitHub (Nov 15, 2024):

Closed as I was missing a return in my toast.

<!-- gh-comment-id:2478877724 --> @kylegrahammatzen commented on GitHub (Nov 15, 2024): Closed as I was missing a return in my toast.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#25638