我正在执行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:指定了无效的令牌
[也许您也需要清除状态,以防万一有一些代码查看状态并执行某些代码而不应该这样做