nextjs-auth0: Hosting via Vercel not working because of AUTH0_BASE_URL.
Description
Hi, I would like to reopen https://github.com/auth0/nextjs-auth0/issues/383, as https://github.com/auth0/nextjs-auth0/pull/404 did not fix the problem, as you can see in the last comments of https://github.com/auth0/nextjs-auth0/issues/383.
The documentation at https://github.com/auth0/nextjs-auth0/blob/main/examples/README.md#assigning-the-auth0_base_url seems wrong to me, as the env key in config and the webpack DefinePlugin don’t work for files in node_module, which are not touched by webpack.
Moreover, on a Vercel side, the VERCEL_URL reference the “by commit domain”, and not the “by PR domain”, so we can’t use auth0 with the standard PR domain.
We have to figure out another way to do this.
Any thoughts about this?
Thanks.
Environment
- Version of this library used: v1.4.0
- Version of the platform or framework used, if applicable: Next 10.2.3 with Vercel
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 32 (11 by maintainers)
I can confirm that committing a
.env.productionwith the following works.Also, specifying
AUTH0_BASE_URLfor your production domain in the Vercel environment config (through GUI or CLI) will properly override what’s defined in the.env.productionfile.@sioquim - I’ve been testing this and assiging
AUTH0_BASE_URLfor the build command (AUTH0_BASE_URL="$VERCEL_URL" npm build) doesn’t work because it only provides theAUTH0_BASE_URLduring the Build Step not during Serverless Function execution when it’s required by the SDK. Am I missing something?https://github.com/auth0/nextjs-auth0/issues/417#issuecomment-877091950 does not work any more.
Ah, ok - thanks for sharing that example repo @tusbar. It looks like the example app was working differently because it was installing the SDK from a relative path
I’ll come up with a different way to resolve #383
I can confirm that the fix does not work.
I have the following entry in the
envsection of mynext.config.js:When my app using
VERCEL_URL=localhost:4000 yarn next start -p 4000and navigating to the api/auth/login route, the joi validation fails with:TypeError: "baseURL" is required.getConfigfrom nextjs-auth0 does not retrieve the environment variable value: indist/config.js,AUTH0_BASE_URLis undefined, sobaseURLis too.ok, thanks @sioquim - I’m going to test that out on the example app and update the guidance if it works
Thanks @sioquim
Would this work?
AUTH0_BASE_URL="$VERCEL_GIT_REPO_SLUG-$VERCEL_GIT_COMMIT_REF-$VERCEL_GIT_REPO_OWNER.vercel.app" yarn buildThe issue is that
process.env.AUTH0_BASE_URLwill not be replaced within the SDK, and the configuration validation will fail at runtime.Here’s a basic example: https://github.com/tusbar/nextjs-auth0-repro
All I did was export a getServerSideProps in pages/index.js
https://github.com/tusbar/nextjs-auth0-repro/commit/fb1db699287111fc2a782d3db495fdcc3348fa7f