SSO plugin does not respect basePath when constructing the redirect URL back to the API #2039

Closed
opened 2026-03-13 09:22:30 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @mprync on GitHub (Sep 29, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Setup SSO plugin, set a basePath with "api"
Sign in to SSO, then the return URL wont contain the base path

Current vs. Expected behavior

Doesn't respect base path vs should respect base path

I would prefer to construct the URL myself.

What version of Better Auth are you using?

1.3.19

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.0.0: Mon Aug 25 21:17:54 PDT 2025; root:xnu-12377.1.9~3/RELEASE_ARM64_T6041",
    "release": "25.0.0",
    "cpuCount": 16,
    "cpuModel": "Apple M4 Max",
    "totalMemory": "48.00 GB",
    "freeMemory": "0.36 GB"
  },
  "node": {
    "version": "v24.5.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.5.1"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "Unknown",
    "config": null
  }
}

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

Backend

Auth config (if applicable)


Additional context

No response

Originally created by @mprync on GitHub (Sep 29, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Setup SSO plugin, set a basePath with "api" Sign in to SSO, then the return URL wont contain the base path ### Current vs. Expected behavior Doesn't respect base path vs should respect base path I would prefer to construct the URL myself. ### What version of Better Auth are you using? 1.3.19 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.0.0: Mon Aug 25 21:17:54 PDT 2025; root:xnu-12377.1.9~3/RELEASE_ARM64_T6041", "release": "25.0.0", "cpuCount": 16, "cpuModel": "Apple M4 Max", "totalMemory": "48.00 GB", "freeMemory": "0.36 GB" }, "node": { "version": "v24.5.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.5.1" }, "frameworks": null, "databases": null, "betterAuth": { "version": "Unknown", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript ``` ### Additional context _No response_
GiteaMirror added the plugin label 2026-03-13 09:22:30 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 29, 2025):

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

You're correct—the SSO plugin in Better Auth v1.3.19 does not automatically respect a separate basePath when constructing redirect URLs. Instead, it builds the redirect URI using only the baseURL context property, so any basePath you want included must be part of baseURL itself. There isn't a built-in way to override or manually construct the redirect URL in the SSO plugin; the logic is internal and doesn't expose hooks or config for this purpose [source].

If you need the base path (like /api) in your redirect URLs, set your baseURL to include it (e.g., baseURL: 'http://localhost:3000/api'). The basePath setting is not used in the SSO plugin's redirect logic, and recent updates to URL utilities and client config don't change this behavior [source].

There is currently no option to construct the redirect URL yourself via plugin config or API. If you need more control, the only workaround is to ensure your baseURL includes the full path you want the SSO plugin to use.

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Sep 29, 2025): <!-- Greeting --> Hi @mprync! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> You're correct—the SSO plugin in Better Auth v1.3.19 does not automatically respect a separate basePath when constructing redirect URLs. Instead, it builds the redirect URI using only the baseURL context property, so any basePath you want included must be part of baseURL itself. There isn't a built-in way to override or manually construct the redirect URL in the SSO plugin; the logic is internal and doesn't expose hooks or config for this purpose [[source](https://github.com/better-auth/better-auth/blob/f6cbdcc84ee5d2971fdcc8b23ff7c174f88cf45b/packages/better-auth/src/plugins/sso/index.ts)]. If you need the base path (like `/api`) in your redirect URLs, set your baseURL to include it (e.g., `baseURL: 'http://localhost:3000/api'`). The basePath setting is not used in the SSO plugin's redirect logic, and recent updates to URL utilities and client config don't change this behavior [[source](https://github.com/better-auth/better-auth/pull/4888)]. There is currently no option to construct the redirect URL yourself via plugin config or API. If you need more control, the only workaround is to ensure your baseURL includes the full path you want the SSO plugin to use. <!-- 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/0116a7fe-ad4a-43c1-b34c-4289042d460c?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/0116a7fe-ad4a-43c1-b34c-4289042d460c?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/0116a7fe-ad4a-43c1-b34c-4289042d460c?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/0116a7fe-ad4a-43c1-b34c-4289042d460c?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/0116a7fe-ad4a-43c1-b34c-4289042d460c?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/0116a7fe-ad4a-43c1-b34c-4289042d460c?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/0116a7fe-ad4a-43c1-b34c-4289042d460c?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&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/4966)
Author
Owner

@Kinfe123 commented on GitHub (Oct 10, 2025):

I cant reproduce this. Could you please provide a minimal reproduction example with your exact Better Auth configuration? and make sure you are better-auth version as well.

@Kinfe123 commented on GitHub (Oct 10, 2025): I cant reproduce this. Could you please provide a minimal reproduction example with your exact Better Auth configuration? and make sure you are better-auth version as well.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2039