We are using axios as our main http request library and JWT tokens for authentication, and it's so easy to select the instance of axios you are using, and modify the headers to be sent as per session basis ..
With this little guy, we are able to set the default headers for all axios calls after a user has authenticated (you'll see we force the cleaning of headers to avoid problems with duplicated Bearers, and to be able to re-use the function to clear out the headers)
We also store the JWT in localStorage, so it gets rehydrated if the user reloads the page ..
Quique Borredá
Passionate about web since 1991
We are using axios as our main http request library and JWT tokens for authentication, and it's so easy to select the instance of axios you are using, and modify the headers to be sent as per session basis ..
export default function setAuthToken(token) { axios.defaults.headers.common['Authorization'] = ''; delete axios.defaults.headers.common['Authorization']; if (token) { axios.defaults.headers.common['Authorization'] = `${token}`; } }With this little guy, we are able to set the default headers for all axios calls after a user has authenticated (you'll see we force the cleaning of headers to avoid problems with duplicated Bearers, and to be able to re-use the function to clear out the headers)
We also store the JWT in localStorage, so it gets rehydrated if the user reloads the page ..
Hope this helps