Answer the question
In order to leave comments, you need to log in
Why is the token not saved when redirecting React and react-router?
Hello.
I use React-router in my project. On the start page there is a login/registration window. After successfully entering the login and password, the server sends a token. I save it in cookies and insert it on subsequent requests to the API. The problem is that when redirecting from the main url "/" to "/application", the token is not read (it displays null in the console). If you reload the page - everything is OK, the token is read.
export function loginWithSocial(key, social) {
return function(dispatch) {
return axios.post(API + "/rest-auth/" + social, {
'access_token':key
})
.then(function(response) {
cookies.set("token", response.data.key);
history.push('/application');
})
.catch(function(response){
})
}
};
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question