Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next-auth/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-auth",
"version": "4.24.11",
"version": "4.25.0",
"description": "Authentication for Next.js",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth.git",
Expand Down
17 changes: 12 additions & 5 deletions packages/next-auth/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,24 @@ async function toInternalRequest(
cookies: parseCookie(req.headers.get("cookie") ?? ""),
providerId: nextauth[1],
error: url.searchParams.get("error") ?? nextauth[1],
origin: detectOrigin(
headers["x-forwarded-host"] ?? headers.host,
headers["x-forwarded-proto"]
),
origin: headers?.host
? `${url.protocol}//${headers.host}`
: detectOrigin(
headers["x-forwarded-host"] ?? headers.host,
headers["x-forwarded-proto"]
),
query,
}
}

const { headers } = req
const host = headers?.["x-forwarded-host"] ?? headers?.host
req.origin = detectOrigin(host, headers?.["x-forwarded-proto"])

req.origin = host
? (process.env.NEXTAUTH_URL?.startsWith("https://") ?? !!process.env.VERCEL
? "https://"
: "http://") + host
: detectOrigin(host, headers?.["x-forwarded-proto"])

return req
}
Expand Down
6 changes: 5 additions & 1 deletion packages/next-auth/src/react/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ export * from "./types"
// 2. When invoked server side the value is picked up from an environment
// variable and defaults to 'http://localhost:3000'.
const __NEXTAUTH: AuthClientConfig = {
baseUrl: parseUrl(process.env.NEXTAUTH_URL ?? process.env.VERCEL_URL).origin,
baseUrl: parseUrl(
typeof window === "undefined"
? process.env.NEXTAUTH_URL ?? process.env.VERCEL_URL
: window.origin
).origin,
basePath: parseUrl(process.env.NEXTAUTH_URL).path,
baseUrlServer: parseUrl(
process.env.NEXTAUTH_URL_INTERNAL ??
Expand Down