Unfortunately, keeping any key in your React client, even if you are using gitignore and an .env
file, is not secure. As pointed out by @ClaudiuCreanga, React environment variables are embedded in the build and are publicly accessible.
You should really only save API keys or secrets in your backend such as Node / Express. You can have your client send a request to your backend API, which can then make the actual API call with the API key and send the data back to your client.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…