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
Ability to load environment variables at runtime, not build time #85
Comments
Yeah, I assumed t3-env already did this! 🥲 It's important for self-hostable applications that are packaged into a docker image, end users should be able to edit the runtime env Would you accept PR for this? I could try to implement a solution |
I think we can make t3-env compatible with next-runtime-env at least! I'll take a look. |
@baptisteArno I would be very happy if, if you find a solution, you share it here. I have been looking for something like this for some time. Thank you very much! |
This works: // src/env.mjs
import { createEnv } from "@t3-oss/env-nextjs";
import { z } from "zod";
const readVariable = (key) => {
if(typeof window === 'undefined') return process.env[key]
return window.__ENV[key]
}
export const env = createEnv({
server: {
DATABASE_URL: z.string().url(),
OPEN_AI_API_KEY: z.string().min(1),
},
client: {
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: z.string().min(1),
},
runtimeEnv: {
DATABASE_URL: process.env.DATABASE_URL,
OPEN_AI_API_KEY: process.env.OPEN_AI_API_KEY,
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY:
readVariable(NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY),
},
}); |
Yes |
Would love to hear of any updates on this issue🤔 |
In the project I'm working we adopted the t3-env lib with nextjs, to work around this validation problem in the build time I added an env var to skip the validation.
env.mjs:
In this way I'm able to skip the validation for the build |
I would like something like this, but for async functions. #146 |
The correct way is what @rochaalexandre posted but |
I wonder if it is possible to load the environment variables at runtime, as with "https://github.com/expatfile/next-runtime-env". This is not possible in the example with nextjs.
The text was updated successfully, but these errors were encountered: