Is it true that keeping confidential API keys in a .env file doesn't completely hide the key in React because you are still able to see this key in the browser?
So what's the right way to store API keys in React? Do I need to retrieve them from the server?
For example:
const [key, setKey] = useState('');
const getApiKey = async () => {
await axios.get("https://example.com/getApiKey").then((res) => { setKey(res) });
}
useEffect(() => {
getApiKey();
}, []);
Do I put it in the state then use it like this?
<StaticGoogleMap
className="google-map"
size="300x300"
apiKey={key}
/>
I thought this way the API key would be still visible to the users in the browser.
I would really appreciate it if someone could explain the right way of securely storing API keys on the frontend. Thanks!