Reputation: 21
I'm writing a web application with Next.js and mobx. How can I pass token (from cookies) for each request to API? Sometimes I should take it from the browser and sometimes from server side (context object). Notice, that I make requests in mobx actions (@action). Thanks in advance!
Upvotes: 0
Views: 364
Reputation: 181
It depends on the way you are calling the API. You can achieve that with Axios for example:
const token = localStorage.get('access_token');
const { data } = awit axios('/api/users', { headers: { Authorization: `bearer ${token}` } });
Upvotes: 0