N
Nuxt2y ago
Thijs

How to handle private keys.

Hi, I have a question. I want to do a POST request to my server with my API key from my .env. I added the key to my runtimeconfig (see screenshot). I uploaded the website to Netlify, set there my env vars, and tried to POST my function. But I get a 403 because my key isn't pushed? What am I missing? When I paste the key as a string in my const client = .... everything works fine.
No description
No description
11 Replies
manniL
manniL2y ago
Where do you create the client? Private keys are only available on server side
Thijs
ThijsOP2y ago
In my register.vue How can you do it else than?
manniL
manniL2y ago
Well Either publish the key or write a “wrapper API” via nitro Should the token be secret?
Thijs
ThijsOP2y ago
Yes I thought you could "just" add .env. variables in netlify and then use process.env.KEY And call those in your /pages/template.vue
manniL
manniL2y ago
The point is If you need to call that on the client side, there is no way without storing the key in the frontend or calling an API which “Proxies” the request to directus with the key The latter will keep your keys safe Why does the key need to be secret? What kind of token is it?
Thijs
ThijsOP2y ago
In this particular case it doesn't need to be secret But say we use an API key of Mapbox or so Then you want that secret because otherwise anyone can use your token How would you handle with that case? @manniL / TheAlexLichter
Thijs
ThijsOP2y ago
Do something like this? https://stackoverflow.com/a/69624163
Stack Overflow
How to use a private API key with Nuxt (on the client)?
Problem Solved If you're struggling with the same issue, look at the accepted answer which is one way to achieve it by using serverMiddleware I'm using an API which required a private key. I've st...
manniL
manniL2y ago
You usually have a domain lock on these Yes, kinda
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
manniL
manniL2y ago
Yes. Same idea!
Dovendyret
Dovendyret2y ago
I found the Nuxt API Party module to be great for handling secret API keys. You could look into that.
Want results from more Discord servers?
Add your server