nextjs-auth0: v4.4.1: ConfigurationError thrown in pipeline as variables are not available on build time

Checklist

Description

After upgrading our SDK from v4.4.0 to v4.4.1 our webapp won’t build in the pipeline anymore. Our AUTH0_... variables are defined in the Azure App Service (so they’re only available in the backend), but not in the build step. We’re not planning on adding those non-NEXT_PUBLIC_ variables to the pipeline either, as that might confuse developers since they’re not the variables actually used in the webapp; non-NEXT_PUBLIC_ variables are defined in the App Service.

Would it be possible to create a way to disable the validation of variables by e.g. setting a single environment variable, like AUTH0_OVERRIDE_VARIABLE_VALIDATION? Not relevant to this specific issue, but how was this change only a patch instead of a minor version bump?

Reproduction

  1. Try to build your Next 14 WebApp without all required non-NEXT_PUBLIC_ variables (like domain, clientId, appBaseUrl, secret and clientAuthentication)
  2. Notice that building is not possible
  3. Find out that disabling the validation is not possible

Additional context

No response

nextjs-auth0 version

v4.4.1

Next.js version

v14.2.26

Node.js version

v20.10.0

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 17 (6 by maintainers)

Most upvoted comments

This broke builds for my team as well. I really don’t think this validation check has much value in the context of a build. Supplying placeholder environment variables at build time has no bearing on whether or not they are being properly configured at run time.

Further, supplying run time secrets at build time is something that should be discouraged. And this validation actively encourages it. Many are going to assume the actual values are required, not just placeholders.

To not rely on the behavior to be able to instantiate an SDK without providing the required configuration

Can you please provide a suggestion, i.e a way to initialise SDK at runtime with correct properties besides faking with placeholders?

Same issue here, this is breaking our NextJS docker builds. I think we had this issue in the early v4 betas and it was fixed. We will have to roll back to an earlier release.

First of all it was a breaking change for us, because obviously many build builds agnostic of environment variables with an idea to initialise Auth0Client in runtime with params passed via process.env. With update from v4.4.0 to v4.4.1, our builds start to fail. https://github.com/auth0/nextjs-auth0/pull/2026#issuecomment-2782683088

Ok, so how do you suggest we get our builds to work without using valid variables?

By using placeholders. If the build worked without value, it should work with placeholders as we verify the existence, not the validity.

However, having talked about this internally, we are considering changing this to be a warning and not break.

Even though I believe an error is what we should be doing, I think this should have been like this from the beginning and this is a fair middleground.

Having the same issue myself with Azure App Service.

I think it is a mistake to enforce the lack of runtime validation checks because you want to be able to instantiate the SDK without the required properties.

The root cause of the issue here isn’t the validation we added, but the fact that the SDK is being instantiated without the required configuration and the solution is to:

  • Ensure the configuration is provided
  • Do not instantiate the SDK when the configuration isn’t available.

That said, given the fact that this broke more people then we would have hoped for (and we should have had this check from the beginning, but we didn’t so that is on us), we are going to go ahead and move this to be a warning. But I would still encourage to not rely on the behavior to be able to instantiate an SDK without providing the required configuration.

Closing this, as the PR to change to a warning will go out with the next release.

Lovely, if empty strings as values will work then we can definitely accommodate that.

We create a single docker build using npm run build and then deploy this to various environments with the AUTH0 variables being set per-environment in advance of npm start. We use a different set of Auth0 credentials for different target environments. It will be very difficult for us to use variables when we create the build.

I don’t understand why this change is necessary, it was already addressed in an earlier beta. Please let us opt out of this behaviour or perhaps suggest a way to opt out of the auth0 client code executing during the build…? I assume the nextjs middleware is executing. All of our app pages are dynamic.

Unless I’m missing something this pattern of reusing a single build in different envs is quite common.