Skip to content

Commit 00e6f8f

Browse files
fix: ignore / for NEXTAUTH_URL path, infer NEXTAUTH_SECRET (#9955)
fix: ignore `/` for `NEXTAUTH_URL` path, detect `NEXTAUTH_SECRET`
1 parent 0815178 commit 00e6f8f

File tree

1 file changed

+6
-1
lines changed
  • packages/next-auth/src/lib

1 file changed

+6
-1
lines changed

packages/next-auth/src/lib/env.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,17 @@ export function reqWithEnvURL(req: NextRequest): NextRequest {
1515
* For backwards compatibility, `next-auth` checks for `NEXTAUTH_URL`
1616
* and the `basePath` by default is `/api/auth` instead of `/auth`
1717
* (which is the default for all other Auth.js integrations).
18+
*
19+
* For the same reason, `NEXTAUTH_SECRET` is also checked.
1820
*/
1921
export function setEnvDefaults(config: NextAuthConfig) {
2022
try {
23+
config.secret ??= process.env.AUTH_SECRET ?? process.env.NEXTAUTH_SECRET
2124
const url = process.env.AUTH_URL ?? process.env.NEXTAUTH_URL
2225
if (!url) return
23-
config.basePath ||= new URL(url).pathname
26+
const { pathname } = new URL(url)
27+
if (pathname === "/") return
28+
config.basePath ||= pathname
2429
} catch {
2530
} finally {
2631
config.basePath ||= "/api/auth"

0 commit comments

Comments
 (0)