Let's say that I have an API token that I want to live server side. I have it implemented as an environment variable, and was wondering if there was an easy way to add the authorization header with the bearer token to all requests (axios or fetch) that I make in the API folder of pages, without having to enter it every time. If I create an axios instance in a lib folder or something, I'm assuming that will expose it to the client side, or am I wrong about that?
#Attach API token to requests made server side
6 messages · Page 1 of 1 (latest)
If I create an axios instance in a lib folder or something, I'm assuming that will expose it to the client side, or am I wrong about that?
its fine as long as you only use it in the server files and dont import it anywhere else
you can also do the same with fetch by defining a function and use it everywhere