Open API plugin doesn't respect baseUrl #1311

Closed
opened 2026-03-13 08:32:18 -05:00 by GiteaMirror · 7 comments
Owner

Originally created by @PodkopovP on GitHub (Jun 5, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Ex:

  1. Set-up a new NextJS app
  2. Set basePath in next.config to "/test"
  3. Set-up Better Auth, with OpenAPI
  4. Set baseUrl of betterAuth instance to "http://localhost/test/api/auth"
  5. View documentation, see "servers" path is always "/api/auth", rather than "/test/api/auth"

Current vs. Expected behavior

The base server path provided by the Open API plugin seems to be fixed to "/api/auth" - this should respect the baseUrl, and basePath configured to Better Auth.

What version of Better Auth are you using?

1.2.8

Provide environment information

- OS Mac

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

Package, Other

Auth config (if applicable)

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

Additional context

{
...,
plugins: [OpenApi()],
baseUrl: "http://localhost/test/api/auth"
}

Originally created by @PodkopovP on GitHub (Jun 5, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Ex: 1. Set-up a new NextJS app 2. Set basePath in next.config to "/test" 3. Set-up Better Auth, with OpenAPI 4. Set baseUrl of betterAuth instance to "http://localhost/test/api/auth" 5. View documentation, see "servers" path is always "/api/auth", rather than "/test/api/auth" ### Current vs. Expected behavior The base server path provided by the Open API plugin seems to be fixed to "/api/auth" - this should respect the baseUrl, and basePath configured to Better Auth. ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash - OS Mac ``` ### Which area(s) are affected? (Select all that apply) Package, Other ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context { ..., plugins: [OpenApi()], baseUrl: "http://localhost/test/api/auth" }
Author
Owner

@PodkopovP commented on GitHub (Jun 5, 2025):

Also it doesn't respect user.fields overrides

@PodkopovP commented on GitHub (Jun 5, 2025): Also it doesn't respect user.fields overrides
Author
Owner

@Kinfe123 commented on GitHub (Jun 5, 2025):

if you set the baseUrl along with path components , basePath will be ignored.

@Kinfe123 commented on GitHub (Jun 5, 2025): if you set the baseUrl along with path components , basePath will be ignored.
Author
Owner

@PodkopovP commented on GitHub (Jun 5, 2025):

path

I'm aware, I tested both separately and neither work

@PodkopovP commented on GitHub (Jun 5, 2025): > path I'm aware, I tested both separately and neither work
Author
Owner

@Kinfe123 commented on GitHub (Jun 5, 2025):

If you changed the baseURL to test/api/auth, make sure to also update where you mount your endpoint. By default, it's mounted under api/auth/[...all], so ensure that this path includes the test folder—for example, test/api/auth/[...all]

@Kinfe123 commented on GitHub (Jun 5, 2025): If you changed the baseURL to `test/api/auth`, make sure to also update where you mount your endpoint. By default, it's mounted under api/auth/[...all], so ensure that this path includes the test folder—for example, `test/api/auth/[...all]`
Author
Owner

@PodkopovP commented on GitHub (Jun 6, 2025):

Thanks, again I'm well aware - the issue isn't with any functionality, it's just the server url that the open api plugin generates is incorrect so the documentation is inaccurate

@PodkopovP commented on GitHub (Jun 6, 2025): Thanks, again I'm well aware - the issue isn't with any functionality, it's just the server url that the open api plugin generates is incorrect so the documentation is inaccurate
Author
Owner

@Kinfe123 commented on GitHub (Jun 6, 2025):

If you followed everything above, the HTML is still generated from /test/api/auth/reference. The path in the OpenAPI plugin is just appended at the end — which is /reference by default, if I understand your point correctly.

@Kinfe123 commented on GitHub (Jun 6, 2025): If you followed everything above, the HTML is still generated from /test/api/auth/reference. The path in the OpenAPI plugin is just appended at the end — which is /reference by default, if I understand your point correctly.
Author
Owner

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

Closing this due to inactivity on the thread.

@Kinfe123 commented on GitHub (Aug 10, 2025): Closing this due to inactivity on the thread.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1311