I want to save the token which comes from my login or register response body, and use it on all my other requests without copy pasting it into every request header param, is that possible? (I'm using swagger to test it)
The documentation is really minimal and they dont really mention anything like this.
I think there are some options.
One way is to use the set-cookie of the browser. To implement this, you have to use an express session.
Another way is to save the token received from the server, in local storage and append the token to the header of each request. I think you can implement this using axios interceptor simply.
import axios from 'axios';
const axiosIns = axios.create({ baseURL:
${...}
, });axiosIns.interceptors.request.use((config) => { config['headers'] = { ...(config.headers ?? {}), ...(getToken() ? { Authorization:
Bearer ${getToken()}
} : {}), }; return config; });export default axiosIns;