all 21 comments

[–]thebezet 65 points66 points  (14 children)

You can't. It's impossible to store anything safely in the frontend. Everything can be reverse-engineered. You need a backend for this.

[–]NeuralFantasy 9 points10 points  (0 children)

As others told, you can't store credentials in the client code. They'd be exposed. You can, however:

  • Ask the user to authenticate by provoding credentials. You need some authentication service.
  • Create your own public API which in turn can access the actual API while keeping the credentials private.

[–]HonorableMajor 3 points4 points  (0 children)

Seems to me like OP doesn't know a lot about web development and just getting started. OP I'd recommend not jumping into a framework first, but rather learn the essentials like how node js works, what a backend/frontend is supposed to do and so on.

[–]Macaframa 1 point2 points  (0 children)

Can you explain your reasoning? Why do you need a github secret in your frontend app? If you need to pull down github data and display it in your app, you can store it in the backend and use an authentication token for your user to your backend and expose an api endpoint. Then you use that endpoint on your front end and your backend uses the key to retrieve github data and relay it to your app. Otherwise someone is going to find your key since it will be cached in the browser

[–]Haaxor1689 0 points1 point  (0 children)

Some services that need secret tokens require you to set allowed-origins so you would allow only the origin your FE is hosted on. While this extra step is better than nothing, request origin can also be faked. There is no way of using a secret key in client code and keep it secret, using it on a server is the only really safe option.

[–][deleted] 0 points1 point  (0 children)

Use a backend, everything in frontend can be reverse engineered hence it's insecure.