From 2fb34bab51218b67029981188c3c6e3a17f6895c Mon Sep 17 00:00:00 2001 From: Thang Vu Date: Sun, 26 Feb 2023 01:51:16 +0700 Subject: [PATCH] feat: priortize `NEXTAUTH_URL_INTERNAL` (#6814) --- packages/next-auth/src/utils/detect-host.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/next-auth/src/utils/detect-host.ts b/packages/next-auth/src/utils/detect-host.ts index 8c2d346492..8ab93ef696 100644 --- a/packages/next-auth/src/utils/detect-host.ts +++ b/packages/next-auth/src/utils/detect-host.ts @@ -1,5 +1,10 @@ /** Extract the host from the environment */ export function detectHost(forwardedHost: any) { + // if `NEXTAUTH_URL_INTERNAL` is set, it means NextAuth.js is deployed + // behind a proxy - we prioritize it over `forwardedHost`. + if (process.env.NEXTAUTH_URL_INTERNAL) { + return process.env.NEXTAUTH_URL_INTERNAL + } // If we detect a Vercel environment, we can trust the host if (process.env.VERCEL ?? process.env.AUTH_TRUST_HOST) return forwardedHost