Does the API key need to be public to be used? (Discussion) #247
-
Hi there, I've noticed that you get a hydration error when trying to use a non-public API key in your .env file (in Nextjs, but I imagine this would happen everywhere). I'm fairly certain I've seen that this is required, but I can't find the documentation stating as much anymore. Is this by design, and what is the recommended way to protect your API? Currently, I am setting website restrictions on the API key via Google Cloud, but want to see what everyone else is doing. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Yes, there is no way to load the Google Maps Api in the browser without also providing the API key in the browser (which is public for everyone). Basically there are three ways to protect your key and usage:
|
Beta Was this translation helpful? Give feedback.
-
I store the key in the deployment platform env configuration then I use action to get them and use them. @mrMetalWood , does that mean they are public for the usage? |
Beta Was this translation helpful? Give feedback.
-
Did anyone find a better method? i dont want to expose my maps key to browsers! |
Beta Was this translation helpful? Give feedback.
Yes, there is no way to load the Google Maps Api in the browser without also providing the API key in the browser (which is public for everyone).
Basically there are three ways to protect your key and usage: