Skip to content

Instantly share code, notes, and snippets.

@mauriciord
Created October 2, 2023 18:31
Show Gist options
  • Save mauriciord/6daa19349b07dd703b25bfee75f8cc1f to your computer and use it in GitHub Desktop.
Save mauriciord/6daa19349b07dd703b25bfee75f8cc1f to your computer and use it in GitHub Desktop.
Next Auth ignoring Next Auth env on proxy domains
export default async function auth(req: NextApiRequest, res: NextApiResponse) {
if (process.env.VERCEL) {
// prefer NEXTAUTH_URL, fallback to x-forwarded-host
req.headers['x-forwarded-host'] =
process.env.NEXTAUTH_URL ?? req.headers['x-forwarded-host']
}
return await NextAuth(req, res, authOptions())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment