API key and .env files in nextjs projects
Answered
Hilsa shad posted this in #help-forum
Hilsa shadOP
Hello! I have quastion. Else I write in my .env file my api key like this:
NEXT_PUBLIC_API_KEY=
then it will be visible in the “Network” and it turns out anyone can use it, but if I remove NEXT_PUBLIC then my api key will simply not work, and then what to do? I don't want to specify NEXTPUBLIC.... because that's not safe, is it?Answered by Anay-208 | Ping in replies
prefixing with NEXT_PUBLIC means it is non sensitive key, which you are OK to share to the client.
If its a sensitive, you can only access it in the server
If its a sensitive, you can only access it in the server
14 Replies
prefixing with NEXT_PUBLIC means it is non sensitive key, which you are OK to share to the client.
If its a sensitive, you can only access it in the server
If its a sensitive, you can only access it in the server
Answer
So basically:
- It is undefined because you're trying to access it in the client
- It is undefined because you're trying to access it in the client
@Anay-208 | Ping in replies So basically:
- It is undefined because you're trying to access it in the client
Northern snakehead
never knew this
Hilsa shadOP
Thx
@Hilsa shad Thx
Can you mark solution?
Treeing Feist
Wow never knew this
@Treeing Feist Wow never knew this
Umm, Wait, so beginners never knew these things?
@Treeing Feist Wow never knew this
wait whaaat
y’all were exposing your api keys on the client side????
@tsá y’all were exposing your api keys on the client side????
They prob didn’t know they could create public env cars
@Anay-208 | Ping in replies Umm, Wait, so beginners never knew these things?
Japanese flying squid
prolly ones who never hosted any next backend on vercel
Japanese flying squid
i learnt about them when i was adding clerk auth