Does the `site` option still exist?
See original GitHub issueYour question
I’m wondering if the site field in options exists such as is referenced in #423 ?
What are you trying to do
I’m deploying on Vercel and am attempting to set NEXTAUTH_URL dynamically based on the current deployment URL. Vercel exposes (VERCEL_URL)[https://vercel.com/docs/build-step?query=environment#system-environment-variables] which holds the current deployment URL. I was going to pass this to the site option to dynamically set the redirect/callback URL based on the deployment.
I’m also trying to find if Vercel supports setting an env var to equal another, i.e. I could just do NEXTAUTH_URL=VERCEL_URL, but I haven’t found this yet.
Feedback Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
- Found the documentation helpful
- Found documentation but was incomplete
- Could not find relevant documentation
- Found the example project helpful
- Did not find the example project helpful
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)

Top Related StackOverflow Question
Hi there!
The
siteandbaseUrloptions were removed in v3 and replaced with theNEXTAUTH_URLenvironment variable.The primary reason for this was that, as pages and API routes run as isolated functions under Serverless, there wasn’t a practical way to share configuration for the canonical site URL between them and that the approach in v2 (of using secure cookie with a payload to handle basic URL configuration) didn’t work 100% of the time.
I’d wanted to avoid using an environment variable for something like this, but the only other option would be to split configuration off into a separate file and include it in both the front end and the back end. However, this would require MULTIPLE configuration files (as you wouldn’t want things like SECRET or CLIENT ID values leaking into the front end bundle) so wasn’t a great solution either.
Using an environment variable for this seems like the least worst option for now, as it’s available to ALL pages and API routes in an app automatically, even if it is a bit weird. I do have thoughts on how we might improve the developer experience in future, but I don’t see us ever breaking this option.
Note you can ad a custom path to this value e.g.
NEXTAUTH_URL=https://ww.example.comis valid (with the default base ath of/api/auth) but you could also specifyNEXTAUTH_URL=https://ww.example.com/custom-base-path/api/authto use a custom base path for the API route.The
VERCEL_URLis a fallback but it’s not currently a great experience as it’s a random hostname for an instance rather than the canonical URL for a deployment. So, it might work well for email or a credentials provider, but you probably want to set it explicitly for OAuth, as typically URLs for callback URLs have to be very explicit (and can’t just be at a domain).This is developer pain I’m also interested in easing in future releases! The Vercel team might also drop a solution to this at some point, which we can then take advantage of.
The one thing that confused me about the
VERCEL_URLis that I had to go and set it explicitly for it to be populated - I wasn’t seeing it set by default, so still wasn’t ideal for tihings like Pull Request environments.Oh interesting! That’s great to know, I just need to unset that variable on my other deployments 👌 thanks!