Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
What can be recommended here.
When logging in, store the token in the cookie and application storage.
If you use axios, then you can store the token in the default headers.
Example using redux, js-cookie and axios:
cookie.set('token', token);
dispatch(setToken(token)); // если не используете Redux, тут будет this.setState
axios.defaults.headers.common.Authorization = `Bearer ${token}`;
const token = cookie.get('token');
if (token) {
dispatch(setToken(token));
axios.defaults.headers.common.Authorization = `Bearer ${token}`;
// other actions
}
dispatch(deleteToken());
cookie.erase('token');
delete axios.defaults.headers.common.Authorization;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question