[GH-ISSUE #3451] Demo does not work with sign in with social provider invalid_code #26930

Closed
opened 2026-04-17 17:40:51 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @iamsahebgiri on GitHub (Jul 18, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3451

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Image

Current vs. Expected behavior

Image

What version of Better Auth are you using?

1.12.12

Provide environment information

Demo

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

Other

Auth config (if applicable)

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

Additional context

No response

Originally created by @iamsahebgiri on GitHub (Jul 18, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3451 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce <img width="1004" height="866" alt="Image" src="https://github.com/user-attachments/assets/cfcab726-95c7-43fd-b983-9e022c9826d6" /> ### Current vs. Expected behavior <img width="1004" height="866" alt="Image" src="https://github.com/user-attachments/assets/a97d7b48-7fd4-42be-8776-9b62ef6c933f" /> ### What version of Better Auth are you using? 1.12.12 ### Provide environment information ```bash Demo ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-17 17:40:51 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 18, 2025):

Hi @iamsahebgiri! I'm Dosu and I’m helping the better-auth team.

The demo is returning an invalid_code error for social sign-in because no social providers are configured in your Better Auth setup. Social login (like Google, GitHub, etc.) requires you to explicitly add provider credentials (client ID, client secret, and correct redirect URIs) to your config—even in the demo environment. Without this, any attempt to sign in with a social provider will fail at the OAuth callback step, triggering errors like invalid_code or oauth_provider_not_found (source).

To enable social login, add a socialProviders section to your config. For example, to add Google:

import { betterAuth } from "better-auth";
export const auth = betterAuth({
  emailAndPassword: { enabled: true },
  socialProviders: {
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
      // Optionally: scopes, redirectURI, etc.
    },
  },
});

Make sure your OAuth app's redirect URI matches exactly between your provider's dashboard, your Better Auth config, and the actual request. Common pitfalls that can also cause invalid_code include mismatched redirect URIs, missing or expired PKCE/code_verifier, or cookie/session issues between the auth request and callback (source).

Once you add the necessary provider configuration and credentials, social sign-in should work as expected.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

<!-- gh-comment-id:3090320561 --> @dosubot[bot] commented on GitHub (Jul 18, 2025): <!-- Greeting --> Hi @iamsahebgiri! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The demo is returning an `invalid_code` error for social sign-in because no social providers are configured in your Better Auth setup. Social login (like Google, GitHub, etc.) requires you to explicitly add provider credentials (client ID, client secret, and correct redirect URIs) to your config—even in the demo environment. Without this, any attempt to sign in with a social provider will fail at the OAuth callback step, triggering errors like `invalid_code` or `oauth_provider_not_found` ([source](https://github.com/better-auth/better-auth/blob/847fc9bfda368e24b25462c30c46115e0ccb00f6/packages/better-auth/src/api/routes/callback.ts)). To enable social login, add a `socialProviders` section to your config. For example, to add Google: ```typescript import { betterAuth } from "better-auth"; export const auth = betterAuth({ emailAndPassword: { enabled: true }, socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, // Optionally: scopes, redirectURI, etc. }, }, }); ``` Make sure your OAuth app's redirect URI matches exactly between your provider's dashboard, your Better Auth config, and the actual request. Common pitfalls that can also cause `invalid_code` include mismatched redirect URIs, missing or expired PKCE/code_verifier, or cookie/session issues between the auth request and callback ([source](https://github.com/better-auth/better-auth/issues/3401)). Once you add the necessary provider configuration and credentials, social sign-in should work as expected. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/c3a95f7f-4eaa-4688-92ba-5be51768e4be?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/c3a95f7f-4eaa-4688-92ba-5be51768e4be?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/c3a95f7f-4eaa-4688-92ba-5be51768e4be?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/c3a95f7f-4eaa-4688-92ba-5be51768e4be?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/c3a95f7f-4eaa-4688-92ba-5be51768e4be?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/c3a95f7f-4eaa-4688-92ba-5be51768e4be?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/c3a95f7f-4eaa-4688-92ba-5be51768e4be?feedback_type=other)</sup>&nbsp;&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3451)
Author
Owner

@Kinfe123 commented on GitHub (Jul 19, 2025):

it should be fixed by now.

<!-- gh-comment-id:3091356819 --> @Kinfe123 commented on GitHub (Jul 19, 2025): it should be fixed by now.
Author
Owner

@iamsahebgiri commented on GitHub (Jul 19, 2025):

it should be fixed by now.

Hey can you share us the fix PR?

<!-- gh-comment-id:3091513088 --> @iamsahebgiri commented on GitHub (Jul 19, 2025): > it should be fixed by now. Hey can you share us the fix PR?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#26930