How to store user-entered API key and access in server/api

A user inputs their api-key in an input field. I want to store it safely and use it everytime I make calls from a server/api route. Is there any way to access a global variable on server-side without having to send it in the body of the get request each time? I have tried useState and pinia store, but I cannot access these in server/api routes
No description
5 Replies
Voltz
Voltz5mo ago
Just make a variable in like a server util like a map or something that maps the user id to the key, or store it in a db and fetch the api key for the user otherwise it won’t persist
AxelSorensen
AxelSorensenOP5mo ago
I only want it to persist during the session. I don't do any user login
Voltz
Voltz5mo ago
You can set a unique session token for the user in like a cookie or something and use that And then map that cookie to their api token
AxelSorensen
AxelSorensenOP5mo ago
But can I access that in my api route without sending it through the body?
Voltz
Voltz5mo ago
Yeah you would just access the util for it
Want results from more Discord servers?
Add your server