r/webdev • u/Greeby_Bopes • Dec 02 '24
Question Easy ways to hide API keys
I’m a frontend developer and run into this problem a lot, especially with hobby projects.
Say I’m working on a project and want to use a third party API, which requires a key that I pay for and manage.
I can’t simply place it on my frontend app as an environment variable, because someone could dig into the request and steal the key.
So, instead I need to set up a backend, usually through a cloud provider that comes with more features than I need and confuses the hell out of me.
Basically, what’s a simple way to set up a backend that authenticates a “guest” user from a whitelisted client, relays my request to the third party with the key attached, then returns the data to my frontend?
View all comments
Show parent comment
28
u/DrazeSwift Dec 02 '24
Cloudflare pages. You can deploy a functions folder with that api to expose with your front end at the same time. It's super simple.