Redux-react jwt-decode error InvalidTokenError: Invalid token specified
Redux-react jwt-decode error InvalidTokenError: Invalid token specified
我在做react-redux授权,使用action时报错"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: 指定的令牌无效
也许你也需要清除状态,以防万一有一些代码查看状态并执行一些它不应该
我在做react-redux授权,使用action时报错"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: 指定的令牌无效
也许你也需要清除状态,以防万一有一些代码查看状态并执行一些它不应该