[GH-ISSUE #1276] Allow Next.js rewrites for /api/auth/jwks #8670

Closed
opened 2026-04-13 03:49:37 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @shadiramadan on GitHub (Jan 24, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1276

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Configure a rewrite:

    rewrites: async () => [
      {
        source: "/.well-known/jwks.json",
        destination: "/api/auth/jwks",
      },
    ]

Make requests to http://localhost:3000/.well-known/jwks.json

You will see logs containing:

[better-call]: Make sure the URL has the basePath (/api/auth).
 GET /.well-known/jwks.json 404 in 39ms
[better-call]: Make sure the URL has the basePath (/api/auth).
 GET /.well-known/jwks.json 404 in 41ms

Current vs. Expected behavior

It seems better-auth is enforcing that requests need to have /api/auth as the basePath- but I think this requirement is too strict-
/.well-known/jwks.json is a standard jwks location, rewrites should be allowed.

(There are also a well-known location for openid-configuration which would be useful for the OIDC plugin).

What version of Better Auth are you using?

1.1.14

Provide environment information

- macOS 15.2
- Chrome / curl

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

Backend, Other

Auth config (if applicable)

import { betterAuth } from "better-auth"
import { jwt } from "better-auth/plugins";
export const auth = betterAuth({
  plugins: [jwt()],
});

Additional context

No response

Originally created by @shadiramadan on GitHub (Jan 24, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1276 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Configure a rewrite: ```typescript rewrites: async () => [ { source: "/.well-known/jwks.json", destination: "/api/auth/jwks", }, ] ``` Make requests to `http://localhost:3000/.well-known/jwks.json` You will see logs containing: ``` [better-call]: Make sure the URL has the basePath (/api/auth). GET /.well-known/jwks.json 404 in 39ms [better-call]: Make sure the URL has the basePath (/api/auth). GET /.well-known/jwks.json 404 in 41ms ``` ### Current vs. Expected behavior It seems `better-auth` is enforcing that requests need to have `/api/auth` as the basePath- but I think this requirement is too strict- `/.well-known/jwks.json` is a standard jwks location, rewrites should be allowed. (There are also a well-known location for openid-configuration which would be useful for the OIDC plugin). ### What version of Better Auth are you using? 1.1.14 ### Provide environment information ```bash - macOS 15.2 - Chrome / curl ``` ### Which area(s) are affected? (Select all that apply) Backend, Other ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" import { jwt } from "better-auth/plugins"; export const auth = betterAuth({ plugins: [jwt()], }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 03:49:37 -05:00
Author
Owner

@Bekacru commented on GitHub (Feb 3, 2025):

You should use redirects instead. rewrite doesn't change the request url.

<!-- gh-comment-id:2631182519 --> @Bekacru commented on GitHub (Feb 3, 2025): You should use `redirects` instead. rewrite doesn't change the request url.
Author
Owner

@shadiramadan commented on GitHub (Feb 7, 2025):

I guess this works- it's just an extra round trip. The call is cached anyways though so I'll mark this solved.

<!-- gh-comment-id:2642559892 --> @shadiramadan commented on GitHub (Feb 7, 2025): I guess this works- it's just an extra round trip. The call is cached anyways though so I'll mark this solved.
Author
Owner

@coopbri commented on GitHub (Apr 25, 2025):

Is it possible at all to use rewrites? Many OIDC RP (and other auth) libraries depend on nesting well-known endpoints directly under the apex domain, e.g. https://example.com/.well-known/jwks, https://example.com/.well-known/openid-configuration so require custom configuration

.well-known spec ref: https://datatracker.ietf.org/doc/html/rfc8615

<!-- gh-comment-id:2829648557 --> @coopbri commented on GitHub (Apr 25, 2025): Is it possible at all to use `rewrites`? Many OIDC RP (and other auth) libraries depend on nesting well-known endpoints directly under the apex domain, e.g. `https://example.com/.well-known/jwks`, `https://example.com/.well-known/openid-configuration` so require custom configuration `.well-known` spec ref: https://datatracker.ietf.org/doc/html/rfc8615
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8670