[GH-ISSUE #2337] Doesn't always respect NextJS basepath #9154

Closed
opened 2026-04-13 04:31:04 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @PodkopovP on GitHub (Apr 17, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2337

Originally assigned to: @ping-maxwell on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

The NextJS base path isn't always respected, with it sometimes using the root as the base path.

Current vs. Expected behavior

If I set a basePath of '/test', after login I expect to be redirected to '/test'. Currently, however, it'll redirect me to '/'

What version of Better Auth are you using?

1.2.7

Provide environment information

- Mac
- Chrome

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

Backend

Auth config (if applicable)

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

Additional context

No response

Originally created by @PodkopovP on GitHub (Apr 17, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2337 Originally assigned to: @ping-maxwell on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce The NextJS base path isn't always respected, with it sometimes using the root as the base path. ### Current vs. Expected behavior If I set a basePath of '/test', after login I expect to be redirected to '/test'. Currently, however, it'll redirect me to '/' ### What version of Better Auth are you using? 1.2.7 ### Provide environment information ```bash - Mac - Chrome ``` ### Which area(s) are affected? (Select all that apply) Backend ### 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-13 04:31:04 -05:00
Author
Owner

@ping-maxwell commented on GitHub (Apr 20, 2025):

basePath is your auth API endpoint base-path, and doesn't relate to callback urls or redirect urls.
In most cases, the basePath is /api/auth.

Please refer to our docs:

Image https://www.better-auth.com/docs/reference/options#basepath
<!-- gh-comment-id:2817120338 --> @ping-maxwell commented on GitHub (Apr 20, 2025): `basePath` is your auth API endpoint base-path, and doesn't relate to callback urls or redirect urls. In most cases, the `basePath` is `/api/auth`. Please refer to our docs: <img width="851" alt="Image" src="https://github.com/user-attachments/assets/672ab15b-d6bb-46db-951b-bf5a7b8f3f00" /> https://www.better-auth.com/docs/reference/options#basepath
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9154