-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add option to define NEXTAUTH_URL
via next runtime config
#1168
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/nextauthjs/next-auth/pjd7ivkmd |
I've left a comment on this in #1156. I think I get where you are going with this but don't think this a direction we want to go in as I don't think it does what people would hope it does (in the case of most OAuth providers) and I think it would probably cause confusion. I did considering building it this way originally, and explored this with v2.x (originally v2 used an option) but it turns out it creates some interesting problems; especially for API route handling on some hosting platforms; and a race condition that was hard to spot. I lamentably chose a single env var as the least worst option. If you could frame the conceptional challenge - e.g. "signing in with Google on Pull Request instances" and include any constraints (e.g. must support JWT sessions / must support a database, etc. - perhaps we can come up with some approaches? |
What:
Resolves #1156, this PR adds an option to define
NEXTAUTH_URL
via Next.js runtime configuration.Why:
By design, NextAuth.js retrieves
NEXTAUTH_URL
value via environment variables. Some cases requires dynamically generated canonical URL (e.g. multi-stage environments and multi-tenancy websites) and cannot set environment variables dynamically (e.g. Vercel for prod/prev/dev environments).With this proposed PR, NextAuth.js can read
NEXTAUTH_URL
value from Next.js runtime configurations viapublicRuntimeConfig.NEXTAUTH_URL
property on the project'snext.config.js
file.How:
This is approached by creating a function which returns either from
NEXTAUTH_URL
environment variable or from the runtime configuration. If via env, the runtime config will be ignored.Checklist:
Additional notes:
NEXTAUTH_URL
via Vercel's system environment variablesnext
is a dev dependency but is being used in server/client code, probably change as peer dependency?Note to maintainers:
This PR is heavily opinionated and only serves as a temporary solution for those who really need a way to dynamically set
NEXTAUTH_URL
. If there is a better way to implement, or this approach is not aligned with NextAuth.js architecture, or anything, merge is optional. ✌🏻