useRuntimeConfig() is returning undefined values
In my
.env
file I have something like this:
In my nuxt.config.ts
file I have this:
But when I try to access that value like this:
It just prints out undefined
.
Yet if I have this in my template code on that same page:
I can see the value show up when I reload the page and then immediately disappear. What the heck? It's like loginDomains does have the value but then it gets set to undefined without me doing anything?9 Replies
Something messing up on hydration?
Hmm.. this works:
This doesn't:
_PUBLIC seems wrong here
if you don't use it in public
?
runtimeConfig: {
supabaseUrl: process.env.NUXT_PUBLIC_SUPABASE_URL,
supabaseKey: process.env.NUXT_PUBLIC_SUPABASE_KEY,
appUrl: process.env.NUXT_PUBLIC_APP_URL,
loginDomains: process.env.NUXT_PUBLIC_LOGIN_DOMAINS,
},
Alexander Lichter
YouTube
Nuxt's runtimeConfig - The most common mistake
🤯 Throughout my projects, consultancies and code reviews I came across lots of interesting findings - also with regards to Nuxt's runtimeConfig feature. Repeatedly I noticed ONE big mistake though which you might do at this very moment in your project. In this video, explain what it is, why you shouldn't do it and how to use runtimeConfig correc...
it should be process.env.NUXT_SUPABASE_URL
not
NUXT_PUBLIC_
unless it is in runtimeConfig.public.supabaseUrlOk I don't understand but I'll continue to read docs and this vid and hopefully it will click
Appreciate the help
Ok so why does this work:
But this doesn't
useRuntimeConfig() doens't work for public runtime config?
I see. I can't destructure the public ones
@Dilly, do this instead
And also make sure your Nuxt config looks like this:
Thanks. It's been a little while since I worked with runtimeConfig. I totally forgot there was a public property which was my main issue.
PS: don’t add any secret key inside public because it’ll be exposed in a script element in the DOM