我是React和Redux的新手,我一直在关注Stephen Grider的Advanced React和Redux课程,我正在进行身份验证的客户端.我已经在我的本地存储上保存了一个令牌,所有内容似乎都正常工作,直到我刷新页面.当我登录/注册导航更改以显示注销按钮但是如果我手动刷新页面,导航将更改为显示登录/注册按钮.
我真的很陌生,不知道我应该包含什么作为代码片段.我将留下reducer和actions/index.js.另外这是我的git仓库一个LIK.
动作/ index.js
import axios from 'axios';
import { browserHistory } from 'react-router';
import { push } from 'react-router-redux';
import { AUTH_USER, UNAUTH_USER, AUTH_ERROR } from './types';
const API_URL = 'http://localhost:3000';
export function signinUser({ username, password }) {
return function(dispatch) {
// Submit username/password to the server
axios
.post(`${API_URL}/signin`, { username, password })
.then(response => {
// If request is good...
// - Update state o indicate user is authenticated
dispatch({ type: AUTH_USER });
// …Run Code Online (Sandbox Code Playgroud)