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
5 Replies
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
I only want it to persist during the session. I don't do any user login
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
But can I access that in my api route without sending it through the body?
Yeah you would just access the util for it