unable to access environment variable , it says undefined
Answered
Cape lion posted this in #help-forum
Cape lionOP
I am trying to access the env variable within helper folder where i am creating a method to upload file to azure and the secret key become undefined
the same thing if i import on backend api's or if even i use in server components it works fine and i can see the env variable in my console
the env file is on right place as i am accessing different env varaible in different file already like DB_URI etc it works juts fine but for this file idk what happening
the same thing if i import on backend api's or if even i use in server components it works fine and i can see the env variable in my console
the env file is on right place as i am accessing different env varaible in different file already like DB_URI etc it works juts fine but for this file idk what happening
Answered by riský
do you want to access the env var on browser? If so, prefix the name with [
NEXT_PUBLIC_](https://nextjs.org/docs/app/building-your-application/configuring/environment-variables#bundling-environment-variables-for-the-browser)16 Replies
@Cape lion I am trying to access the env variable within helper folder where i am creating a method to upload file to azure and the secret key become undefined
the same thing if i import on backend api's or if even i use in server components it works fine and i can see the env variable in my console
the env file is on right place as i am accessing different env varaible in different file already like DB_URI etc it works juts fine but for this file idk what happening
do you want to access the env var on browser? If so, prefix the name with [
NEXT_PUBLIC_](https://nextjs.org/docs/app/building-your-application/configuring/environment-variables#bundling-environment-variables-for-the-browser)Answer
Cape lionOP
yup i think so i am access it in helper folder to upload a file
directly from form mean client componenty
let me know how updating the name to prefix that goes, and note that as its on browser, you shouldn't put anything sensitive that the client can see (i can see why you would blur if for here, but make sure it is ok for client shown)
Cape lionOP
of cource it's a secret it a connection string to my azure blob storage
@riský works
but now tell me i don't want that client can access it what the solution for that @riský
@Cape lion but now tell me i don't want that client can access it what the solution for that <@657067112434499595>
wait so who should be able to see this? and who shouldn't?
Cape lionOP
thanks mate , got my answer from here https://stackoverflow.com/questions/73039310/is-using-next-public-to-expose-environmental-variables-to-the-browser-safe
yeah it is kinda safe if you are smart with usage, but idk if you should use it for non safe things
so yeah use it in server like they said
Cape lionOP
yeah i am going to set the necessary limits on Azure and hope it all set, would you mind telling me about refersh token implementation in nextjs 14?
Can you look into this issues , if you can help and find me possible way to implement a Refersh Token logic https://stackoverflow.com/questions/77451492/convert-a-function-into-middleware-in-nextjs-14
@riský
@Cape lion Can you look into this issues , if you can help and find me possible way to implement a Refersh Token logic https://stackoverflow.com/questions/77451492/convert-a-function-into-middleware-in-nextjs-14
can you make a new thread for this (i ams also about to sleep so can't help you for some hours)
Cape lionOP
thanks mate , but i have created a thread actually no one replied lol anyway you can sleep , if you got some time tomorrow please you can ping me
https://nextjs-forum.com/post/1172087509052837898
https://nextjs-forum.com/post/1172087509052837898