DEV Community

Discussion on: How to 'Not Advertise' Your API Key in React Apps

Collapse
 
emtes profile image
Enmanuel de la Nuez

See create-react-app.dev/docs/adding-c...

WARNING: Do not store any secrets (such as private API keys) in your React app!

A solution to consider is to code up a server to hide your key and communicate with API. Then, you can fetch from your server.

Collapse
 
wolfdominion profile image
Hannah

This is really good to know, thank you for sharing this! I'll have to update my article.

Collapse
 
ceckenrode profile image
Christian Eckenrode

To add, if the API key is on the front end at all, even loaded from an env variable at build time, it’s still exposed to anyone who can use their browser’s dev tools.

This does keep it out of the GitHub repo though 🙂