Skip to content
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

async env variables #146

Open
SaadBazaz opened this issue Nov 10, 2023 · 2 comments
Open

async env variables #146

SaadBazaz opened this issue Nov 10, 2023 · 2 comments

Comments

@SaadBazaz
Copy link

Hey,
I was wondering if it was possible to update env variables async at boottime? I have an env variable based on a server-side call, so would love to have something like:

runtimeEnvs: {
    MY_ENV: async () => { return await fetch("myurl.com") }
}
@chungweileong94
Copy link
Contributor

It's possible right now, but not the way you expected.

import { createEnv as createT3Env } from "@t3-oss/env-core";
import { z } from "zod";

async function loadEnv() {
  const value = await fetch("myurl.com").then(async (r) => await r.json());

  return createEnv({
    server: {
      MY_ENV: z.string(),
    },
    runtimeEnv: {
      MY_ENV: value,
    },
  });
}

// Usage
const env = await loadEnv()

@kevinszuchet
Copy link

Did it work for you @SaadBazaz ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants