-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: NEXT_PUBLIC variable access #94
Conversation
Ensure that the `NEXT_PUBLIC_` variable is inlined during builds. https://nextjs.org/docs/app/building-your-application/configuring/environment-variables#bundling-environment-variables-for-the-browser (The above link specifically talks about the browser, but the inlining of NEXT_PUBLIC variables also applies to middleware).
@PaulAsjes I tried out the new version and ran into an issue with the variable still being undefined.
leads to
|
@@ -11,7 +11,7 @@ const WORKOS_COOKIE_DOMAIN = getEnvVariable('WORKOS_COOKIE_DOMAIN'); | |||
const WORKOS_COOKIE_MAX_AGE = getEnvVariable('WORKOS_COOKIE_MAX_AGE'); | |||
const WORKOS_COOKIE_NAME = getEnvVariable('WORKOS_COOKIE_NAME'); | |||
const WORKOS_COOKIE_PASSWORD = getEnvVariable('WORKOS_COOKIE_PASSWORD') ?? ''; | |||
const WORKOS_REDIRECT_URI = getEnvVariable('NEXT_PUBLIC_WORKOS_REDIRECT_URI') ?? ''; | |||
const WORKOS_REDIRECT_URI = process.env.NEXT_PUBLIC_WORKOS_REDIRECT_URI ?? ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is baffling, I wonder why process.env[name]
isn't working as expected. Since getEnvVariable
doesn't add much anymore, would you mind replacing every instance in this file with a direct lookup of process.env
? e.g.
const WORKOS_REDIRECT_URI = process.env.NEXT_PUBLIC_WORKOS_REDIRECT_URI ?? ''; | |
const WORKOS_API_HOSTNAME = process.env..WORKOS_API_HOSTNAME; | |
const WORKOS_API_HTTPS = process.env.WORKOS_API_HTTPS; | |
const WORKOS_API_KEY = process.env.WORKOS_API_KEY ?? ''; | |
const WORKOS_API_PORT = process.env.WORKOS_API_PORT; | |
const WORKOS_CLIENT_ID = process.env.WORKOS_CLIENT_ID ?? ''; | |
const WORKOS_COOKIE_DOMAIN = process.env.WORKOS_COOKIE_DOMAIN; | |
const WORKOS_COOKIE_MAX_AGE = process.env.WORKOS_COOKIE_MAX_AGE; | |
const WORKOS_COOKIE_NAME = process.env.WORKOS_COOKIE_NAME; | |
const WORKOS_COOKIE_PASSWORD = process.env.WORKOS_COOKIE_PASSWORD ?? ''; | |
const WORKOS_REDIRECT_URI = process.env.NEXT_PUBLIC_WORKOS_REDIRECT_URI ?? ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't see the nextjs docs you linked, makes sense now. Thanks for catching!
Ensure that the
NEXT_PUBLIC_
variable is inlined during builds.https://nextjs.org/docs/app/building-your-application/configuring/environment-variables#bundling-environment-variables-for-the-browser
(The above link specifically talks about the browser, but the inlining of NEXT_PUBLIC variables also applies to middleware).