Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redux state would lose in auth.js loginUser #26

Open
sylarmeng opened this issue Jun 22, 2017 · 0 comments
Open

redux state would lose in auth.js loginUser #26

sylarmeng opened this issue Jun 22, 2017 · 0 comments

Comments

@sylarmeng
Copy link

sylarmeng commented Jun 22, 2017

export function loginUser({ email, password }) {
  return function (dispatch) {
    axios.post(`${API_URL}/auth/login`, { email, password })
    .then((response) => {
      cookie.save('token', response.data.token, { path: '/' });
      cookie.save('user', response.data.user, { path: '/' });
      dispatch({ type: AUTH_USER });
      window.location.href = `${CLIENT_ROOT_URL}/dashboard`;
    })
    .catch((error) => {
      errorHandler(dispatch, error.response, AUTH_ERROR);
    });
  };
}

above is login action in auth.js(client----src----actions----auth.js).

If use window.location.href, the page would refresh, redux state would lose, you would always get authenticated state false!

Replace window.location.href with browserHistory, state would be ok!

import { browserHistory } from 'react-router'
browserHistory.push('/some/path')

@joshuaslate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant