M
M
mr_drinkens2017-05-29 18:10:39
React
mr_drinkens, 2017-05-29 18:10:39

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){
  
    })
  }
};

How to get out of the situation? Do a regular redirect with reload via location.href?
Thank you in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question