N
Nuxt2y ago
alexcali

Access environment variables from `store` or `root` folder

I have a .ts file where I would like to read values from my environment variables but anytime I do so, I get undefined. How can I go around this and access env variables from anywhere in my project?
4 Replies
Cue
Cue2y ago
Consider using runtime config without leaking sensitive data.
alexcali
alexcaliOP2y ago
Right, I read about it here (https://nuxt.com/docs/guide/going-further/runtime-config) and it still doesn't look like I'll be able to just use process.env.VAR_NAME. I'd love to be able to just do that, alternatively I can refactor my code. This is file the store/auth.ts:
import { Auth0Client } from "@auth0/auth0-spa-js";

const auth = await new Auth0Client({
domain: "",
clientId: "",
cacheLocation: "localstorage",
authorizationParams: {
redirect_uri: "",
},
});

export default auth;
import { Auth0Client } from "@auth0/auth0-spa-js";

const auth = await new Auth0Client({
domain: "",
clientId: "",
cacheLocation: "localstorage",
authorizationParams: {
redirect_uri: "",
},
});

export default auth;
Maybe this is not the right location for it
Nuxt
Runtime Config · Nuxt Advanced
Nuxt provides a runtime config API to expose configuration within your application.
Cue
Cue2y ago
What do you mean by “I won’t be able to use env vars” with runtime config? The purpose of runtime config working in tandem with env vars is that they are evaluated in the config and passed through to the app therefore not required to use process.env within your app.
alexcali
alexcaliOP2y ago
My idea was to use env variables within certain folders but I guess that's not possible all the time. So, I ended up re-factoring my code to follow what Nuxt reccommends.
Want results from more Discord servers?
Add your server