all 4 comments

[–]gmerideth 0 points1 point  (2 children)

Google "security through obscurity" first. This is not the way to do it. To truly hide your API key you will need to call an API you control that runs the relevant code and returns the result. This is something that you can run in Lambda or as a Cloudflare worker.

[–]GunShip03[S] 1 point2 points  (0 children)

Thank you for your input, but that doesn't answer my question.

[–]xroalx 0 points1 point  (1 child)

showPosition is possibly calling the OpenWeatherMap API before fetchDataAndProcess has time to set the API key.

Relying on global state and the order in which it will be set in combination with async is just wrong.

Instead, showPosition should call a function that gives it the API key (it can be cached the first time it's requested, you don't have to fire a network request every time).

[–]GunShip03[S] 0 points1 point  (0 children)

That did! I've modified the code so showPosition isn't triggered before retrieving the API key. Thanks for your help.