DEV Community

Discussion on: How to hide your API key in React Apps

Collapse
 
ecyrbe profile image
ecyrbe

Unless you are the only user of your web app, do not do this.

If your app is used by other users than you, i'll remind you that API keys do not belong in your front-end.
They belong in your server. Hiding API keys in env variable is wrong, they are still available to your users when downloading the source code. It's a big security breach.
Your API Key is still visible in dev tools when looking at network requests.
If you use netlify, use netlify functions, if you own your own server, do the request with your API Key on your backend.

Collapse
 
casraf profile image
Chen Asraf

You're right, though some services have in mind that they will be used on the client side, so they provide "exposable" client keys that are meant to be okay with staying out in the open. That's usually the case for client-side libraries such as Google Maps, mixpanel, etc.

And then there's the rest of the libraries - that are meant to handle server requests. These usually have much higher permissions and require truly secret API keys, in which case as you said it should stay in the server without being exposed to the users in any way.

Collapse
 
efkumah profile image
Emmanuel Fordjour Kumah

Thanks for the insight , appreciate it