Next.js Discord

Discord Forum

NEXTAUTH_URL - should be known while building?

Unanswered
Golden northern bumble bee posted this in #help-forum
Open in Discord
Golden northern bumble beeOP
I'm building an app image that shouldn't depend on any URLs and instaed receive them in runtime. But I cannot build my app without setting a specific URL. How to fix this?

11 Replies

@Golden northern bumble bee can you explain your trouble a big more?
can't fully understand
Golden northern bumble beeOP
Hi @James4u
Sure.
I have an app that uses next-auth.
When I run npm run build it fails at the info - Collecting page data... stage saying something like:

TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:405:5)
    at new URL (node:internal/url:778:13)
    at parseUrl (/builds/<project>/node_modules/next-auth/utils/parse-url.js:17:16)
    ...


I was able to empirically track down what URL it's talking about. It's NEXTAUTH_URL
I want to have it undefined/empty while building, because it's different for prod/dev/stage
iirc, nextauth requires NEXTAUTH_URL in env or you should put fallback url somewhere else
Golden northern bumble beeOP
Here they say: When deploying to production, set the NEXTAUTH_URL environment variable to the canonical URL of your site.
Deploying, not building. If it matters...
I want to have it undefined/empty while building, because it's different for prod/dev/stage
I don't understand this much - why is it?
Golden northern bumble beeOP
Different auth backends, depending on where we deploy
not only auth, but site urls are different as well
Golden northern bumble beeOP
Any ideas folks?