You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We are storing environment variables in an external service (like Azure App Configuration) and have created an Auth0 instance manually due to this setup:
However, because serverRuntimeConfig is not available in middleware, we attempted to update process.env in next.config.js file and use it for dynamically loading and updating environment variables like this:
When trying to access these dynamically loaded process.env variables in middleware, they return as undefined. This results in errors like TypeError: "issuerBaseURL" must be a valid URI from the withMiddlewareAuthRequired function.
Question:
What is the correct approach to handle dynamically loaded environment variables in this context with @auth0/nextjs-auth0?
Reproduction
Create a New Next.js Project:
Set Up External Configuration Loader:
Create a configuration loader to fetch environment variables dynamically from an external service (like Azure App Configuration). For this example, use a mock function to simulate loading environment variables:
Set up middleware to protect routes and use the manually initialized Auth0 instance:
// middleware.jsimport{NextRequest,NextResponse}from'next/server';import{withMiddlewareAuthRequired}from'@auth0/nextjs-auth0';exportasyncfunctionmiddleware(request){constsecret=process.env.AUTH0_SECRET;// Trying to access dynamically loaded env variableif(!secret){returnNextResponse.redirect('/error');// Redirect if secret is undefined}returnwithMiddlewareAuthRequired(request);}exportconstconfig={matcher: ['/protected-route'],};
Run the Project:
Start the Next.js development server with npm run dev.
Attempt to access the protected route (e.g., /protected-route).
Expected Result:
Middleware should be able to access the dynamically loaded environment variables and perform authentication checks without errors.
Actual Result:
The environment variables loaded asynchronously are undefined in the middleware, causing errors like TypeError: "issuerBaseURL" must be a valid uri.
Repository:
You can create a minimal reproducible example by sharing this setup in a public GitHub repository.
Consistency:
This issue can be reproduced consistently by following the steps above.
Additional context
No response
nextjs-auth0 version
3.1.0
Next.js version
13.5.5
Node.js version
v18.17.0
The text was updated successfully, but these errors were encountered:
that is malware to steal your account; do not under any circumstances download or run it. The post needs to be removed. If you have attempted to run it please have your system cleaned and your account secured immediately.
that is malware to steal your account; do not under any circumstances download or run it. The post needs to be removed. If you have attempted to run it please have your system cleaned and your account secured immediately.
For sure I will not download it :D I didn't know nowadays people try to steal account from github issues page lol
Hope repo owners will remove that comment when there are check my issue
Checklist
Description
We are storing environment variables in an external service (like Azure App Configuration) and have created an Auth0 instance manually due to this setup:
However, because
serverRuntimeConfig
is not available in middleware, we attempted to updateprocess.env
in next.config.js file and use it for dynamically loading and updating environment variables like this:Problem:
When trying to access these dynamically loaded
process.env
variables in middleware, they return asundefined
. This results in errors likeTypeError: "issuerBaseURL" must be a valid URI
from thewithMiddlewareAuthRequired
function.Question:
What is the correct approach to handle dynamically loaded environment variables in this context with
@auth0/nextjs-auth0
?Reproduction
Create a New Next.js Project:
Set Up External Configuration Loader:
Modify
next.config.js
:next.config.js
to load environment variables asynchronously using the loader:Set Up Auth0 Instance Manually:
Create Middleware:
Run the Project:
npm run dev
./protected-route
).Expected Result:
Middleware should be able to access the dynamically loaded environment variables and perform authentication checks without errors.
Actual Result:
The environment variables loaded asynchronously are
undefined
in the middleware, causing errors likeTypeError: "issuerBaseURL" must be a valid uri
.Repository:
You can create a minimal reproducible example by sharing this setup in a public GitHub repository.
Consistency:
This issue can be reproduced consistently by following the steps above.
Additional context
No response
nextjs-auth0 version
3.1.0
Next.js version
13.5.5
Node.js version
v18.17.0
The text was updated successfully, but these errors were encountered: