Next.js Discord

Discord Forum

read env variables value from client component

Answered
West African Lion posted this in #help-forum
Open in Discord
West African LionOP
Is it a good practice if I try to access the env value from client component? For example I have feature flags and wanna access em in a component. Is that secure approach?
Answered by Asian black bear
For environment variables on the client you use variables prefixed with NEXT_PUBLIC_.
View full answer

4 Replies

Asian black bear
For environment variables on the client you use variables prefixed with NEXT_PUBLIC_.
Answer
Asian black bear
Then you can just use process.env.NEXT_PUBLIC_THING
Chum salmon
Adding to that, make sure everything you put in NEXT_PUBLIC are not something secret like secret key and so on.
West African LionOP
Okay, thanks for the answers guys!