[GH-ISSUE #8033] [Bug] cusotm redirectURI not working with better auth #28299

Closed
opened 2026-04-17 19:43:55 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @zhihengGet on GitHub (Feb 18, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8033

Originally assigned to: @himself65 on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. set google redirectURI to https://a.com/auth/callback (without provider)
  2. google redirects back to that url
  3. but better-auth not handle the url , return 404

Current vs. Expected behavior

expeected better-auth to recognize the url without provider in the url itself

in https://www.better-auth.com/docs/concepts/oauth#redirecturi it also mentione we can do it without provider


export const auth = betterAuth({
  // Other configurations...
  socialProviders: {
    google: {
      clientId: "YOUR_GOOGLE_CLIENT_ID",
      clientSecret: "YOUR_GOOGLE_CLIENT_SECRET",
      redirectURI: "https://your-app.com/auth/callback",
    },
  },
});

What version of Better Auth are you using?

latest

System info

windows

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

Backend

Auth config (if applicable)

export const auth = betterAuth({
  // Other configurations...
  socialProviders: {
    google: {
      clientId: "YOUR_GOOGLE_CLIENT_ID",
      clientSecret: "YOUR_GOOGLE_CLIENT_SECRET",
      redirectURI: "https://your-app.com/auth/callback",
    },
  },
});

Additional context

No response

Originally created by @zhihengGet on GitHub (Feb 18, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8033 Originally assigned to: @himself65 on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. set google redirectURI to https://a.com/auth/callback (without provider) 2. google redirects back to that url 3. but better-auth not handle the url , return 404 ### Current vs. Expected behavior expeected better-auth to recognize the url without provider in the url itself in https://www.better-auth.com/docs/concepts/oauth#redirecturi it also mentione we can do it without provider ``` export const auth = betterAuth({ // Other configurations... socialProviders: { google: { clientId: "YOUR_GOOGLE_CLIENT_ID", clientSecret: "YOUR_GOOGLE_CLIENT_SECRET", redirectURI: "https://your-app.com/auth/callback", }, }, }); ``` ### What version of Better Auth are you using? latest ### System info ```bash windows ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript export const auth = betterAuth({ // Other configurations... socialProviders: { google: { clientId: "YOUR_GOOGLE_CLIENT_ID", clientSecret: "YOUR_GOOGLE_CLIENT_SECRET", redirectURI: "https://your-app.com/auth/callback", }, }, }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-17 19:43:56 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Feb 18, 2026):

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

This is expected behavior - Better Auth requires the provider name in the callback URL path. The callback route is registered with the pattern /callback/:id, where :id is used to identify which OAuth provider should handle the callback. Without it, Better Auth returns 404 because it can't determine which provider to use.

The redirectURI configuration tells the OAuth provider where to redirect, but doesn't change Better Auth's internal routing - it still expects requests to hit /callback/google.

Solution: Use the callback URL with the provider name:

redirectURI: "https://a.com/api/auth/callback/google"

Or let Better Auth construct it automatically by setting your baseURL:

baseURL: "https://a.com/api/auth"
// Better Auth will automatically use: https://a.com/api/auth/callback/google

There's a related issue (#3877) where custom redirectURI settings are sometimes ignored. The current architecture requires the provider name in the path for identification.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3918313662 --> @dosubot[bot] commented on GitHub (Feb 18, 2026): <!-- Greeting --> Hi @zhihengGet! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is expected behavior - Better Auth requires the provider name in the callback URL path. The [callback route is registered with the pattern `/callback/:id`](https://github.com/better-auth/better-auth/blob/d3b579e42a707a9037a9210ad14611366b745d2a/packages/better-auth/src/api/routes/callback.ts#L21-L23), where `:id` is used to identify which OAuth provider should handle the callback. Without it, Better Auth returns 404 because it can't determine which provider to use. The `redirectURI` configuration tells the OAuth provider where to redirect, but **doesn't change Better Auth's internal routing** - it still expects requests to hit `/callback/google`. **Solution:** Use the callback URL with the provider name: ```typescript redirectURI: "https://a.com/api/auth/callback/google" ``` Or let Better Auth construct it automatically by setting your `baseURL`: ```typescript baseURL: "https://a.com/api/auth" // Better Auth will automatically use: https://a.com/api/auth/callback/google ``` There's a [related issue (#3877)](https://github.com/better-auth/better-auth/issues/3877) where custom `redirectURI` settings are sometimes ignored. The current architecture requires the provider name in the path for identification. <!-- 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/b04b2e2a-b042-405e-88e8-22440214fd8b?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/b04b2e2a-b042-405e-88e8-22440214fd8b?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/b04b2e2a-b042-405e-88e8-22440214fd8b?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/b04b2e2a-b042-405e-88e8-22440214fd8b?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b04b2e2a-b042-405e-88e8-22440214fd8b?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/b04b2e2a-b042-405e-88e8-22440214fd8b?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/b04b2e2a-b042-405e-88e8-22440214fd8b?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20expected%20behavior%20-%20Better%20Auth%20requires%20the%20provider%20name%20in%20the%20callback%20URL%20path.%20The%20%5Bcallback%20route%20is%20registered%20with%20the%20pattern%20%60/callback/%3Aid%60%5D%28https%3A//github.com/better-auth/better-auth/blob/d3b579e42a707a9037a9210ad14611366b745d2a/packages/better-auth/src/api/routes/callback.ts%23L21-L23%29%2C%20where%20%60%3Aid%60%20is%20used%20to%20identify%20which%20OAuth%20provider%20should%20handle%20the%20callback.%20Without%20it%2C%20Better%20Auth%20returns%20404%20because%20it%20can%27t%20determine%20which%20provider%20to%20use.%0A%0AThe%20%60redirectURI%60%20configuration%20tells%20the%20OAuth%20provider%20where%20to%20redirect%2C%20but%20%2A%2Adoesn%27t%20change%20Better%20Auth%27s%20internal%20routing%2A%2A%20-%20it%20still%20expects%20requests%20to%20hit%20%60/callback/google%60.%0A%0A%2A%2ASolution%3A%2A%2A%20Use%20the%20callback%20URL%20with%20the%20provider%20name%3A%0A%60%60%60typescript%0AredirectURI%3A%20%22https%3A//a.com/api/auth/callback/google%22%0A%60%60%60%0A%0AOr%20let%20Better%20Auth%20construct%20it%20automatically%20by%20setting%20your%20%60baseURL%60%3A%0A%60%60%60typescript%0AbaseURL%3A%20%22https%3A//a.com/api/auth%22%0A//%20Better%20Auth%20will%20automatically%20use%3A%20https%3A//a.com/api/auth/callback/google%0A%60%60%60%0A%0AThere%27s%20a%20%5Brelated%20issue%20%28%233877%29%5D%28https%3A//github.com/better-auth/better-auth/issues/3877%29%20where%20custom%20%60redirectURI%60%20settings%20are%20sometimes%20ignored.%20The%20current%20architecture%20requires%20the%20provider%20name%20in%20the%20path%20for%20identification.)&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/8033)
Author
Owner

@Bekacru commented on GitHub (Feb 18, 2026):

The Dosu bot above is correct.

Better Auth requires the provider name in the callback URL path (/callback/:id) to identify which OAuth provider should handle the callback. The redirectURI configuration tells the OAuth provider where to redirect, but doesn't change Better Auth's internal routing.

Solution: Use the callback URL with the provider name:

redirectURI: "https://a.com/api/auth/callback/google"

Or let Better Auth construct it automatically by setting your baseURL:

baseURL: "https://a.com/api/auth"
// Better Auth will automatically use: https://a.com/api/auth/callback/google

This is the expected behavior by design.

<!-- gh-comment-id:3919512780 --> @Bekacru commented on GitHub (Feb 18, 2026): The Dosu bot above is correct. Better Auth requires the provider name in the callback URL path (`/callback/:id`) to identify which OAuth provider should handle the callback. The `redirectURI` configuration tells the OAuth provider where to redirect, but doesn't change Better Auth's internal routing. **Solution:** Use the callback URL with the provider name: ```typescript redirectURI: "https://a.com/api/auth/callback/google" ``` Or let Better Auth construct it automatically by setting your `baseURL`: ```typescript baseURL: "https://a.com/api/auth" // Better Auth will automatically use: https://a.com/api/auth/callback/google ``` This is the expected behavior by design.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#28299