[GH-ISSUE #1806] NextJs basePath not being followed #17556

Closed
opened 2026-04-15 15:43:41 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @BobanL on GitHub (Mar 13, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1806

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Minimal reproducible repo - https://github.com/BobanL/better-auth-base-path

  1. Make a request to /basePath/api/auth/sign-in/oauth2
  2. redirect_uri in response does not contain basePath

Other scenario

  1. Set basePath in next.config.ts, authClient, and in auth
  2. All requests to /basePath/api/auth return 404

Current vs. Expected behavior

redirect_uri should include the basePath, but it does not.

What version of Better Auth are you using?

1.23

Provide environment information

- OS: Macos
- Browser: Firefox/Chrome
- Other: Postman

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

Backend

Auth config (if applicable)


Additional context

Reproducible example can be found at https://github.com/BobanL/better-auth-base-path.

Originally created by @BobanL on GitHub (Mar 13, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1806 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Minimal reproducible repo - https://github.com/BobanL/better-auth-base-path 1. Make a request to `/basePath/api/auth/sign-in/oauth2` 2. `redirect_uri` in response does not contain basePath Other scenario 1. Set basePath in `next.config.ts`, `authClient`, and in `auth` 2. All requests to `/basePath/api/auth` return 404 ### Current vs. Expected behavior `redirect_uri` should include the basePath, but it does not. ### What version of Better Auth are you using? 1.23 ### Provide environment information ```bash - OS: Macos - Browser: Firefox/Chrome - Other: Postman ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript ``` ### Additional context Reproducible example can be found at https://github.com/BobanL/better-auth-base-path.
GiteaMirror added the lockedbug labels 2026-04-15 15:43:41 -05:00
Author
Owner

@Muhamed-Ragab commented on GitHub (Mar 15, 2025):

You can modify basePath in better-auth config

<!-- gh-comment-id:2726284048 --> @Muhamed-Ragab commented on GitHub (Mar 15, 2025): You can modify basePath in better-auth config
Author
Owner

@JNLei commented on GitHub (Mar 19, 2025):

I think basePath does work, but I do find some issues in your test repo:

  1. basePath in next.config.ts is not used by better-auth, instead, it will be used by next.js to determine the root layout and page (other than default /src).
  2. basePath in auth client is set to be /basePath/api/auth. However, the /api/auth is sitting inside of /scr, that's why all /basePath/api/auth requests return 404 because the path does not exist. You need to create a new directory basePath in /src and then put /api inside of new basePath directly to make next.js resolve the base path.
<!-- gh-comment-id:2735050106 --> @JNLei commented on GitHub (Mar 19, 2025): I think `basePath` does work, but I do find some issues in your test repo: 1. `basePath` in `next.config.ts` is not used by better-auth, instead, it will be used by next.js to determine the root layout and page (other than default `/src`). 2. `basePath` in auth client is set to be `/basePath/api/auth`. However, the `/api/auth` is sitting inside of `/scr`, that's why all `/basePath/api/auth` requests return 404 because the path does not exist. You need to create a new directory `basePath` in `/src` and then put `/api` inside of new `basePath` directly to make next.js resolve the base path.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17556