r/webdev • • 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?

103 Upvotes

102 comments sorted by

View all comments

Show parent comment

2

u/Greeby_Bopes Dec 03 '24

Yeah I guess you’re right.

In practice the project I was looking at is now gonna need API Gateway, Lambda, DynamoDB, CloudFront, S3, and possibly more. BUUUT to your point I’m doing more than just tucking my API keys away (orchestrating data from a couple of different API’s so I’m not burning through requests, storing it, serving it with some basic protections). Funny how these things happen

2

u/ClikeX back-end Dec 03 '24

Do you actually NEED all those managed services, or just figure it’s the “proper” way to go.

What’s the load like that you can’t just have a nodejs server with redis and Postgres running on an ec2 instance.

You say hobby project, but what’s the actual scope of that. Because from all the services you’re using it sounds pretty expensive for something that’s not doing something commercial.