我正在进行react redux授权,在使用操作"LOGOUT"时出现错误这是我的减速器:`
const loginRegLogoutReducer = (state, action) => {
if (!state){
return {}
}
if(localStorage.authToken && action.type === "CHECK_LOGIN" && localStorage.authToken !== null){
let user = jwt(localStorage.authToken)
return {username: user.username, id: user.sub, birthday: user.birthday}
}
if(action.type = 'LOGIN'){
let user = jwt(action.token)
localStorage.setItem('authToken', action.token)
return {username: user.username, id: user.sub, birthday: user.birthday}
}
if(action.type = 'LOGOUT'){
localStorage.removeItem('authToken')
}
return state
}
`这就是我正在做的:
<i class="fa fa-sign-out logout" onClick={() => store.dispatch({type: "LOGOUT"})}/>
所以这给了我一个错误InvalidTokenError:指定的令牌无效
也许你也需要清除状态,以防有一些代码查看状态并执行一些不应该的代码