显然,我一直在收到“未经授权的错误”和“未经授权的错误” 1:{类型:“ GET_ERRORS”,有效负载:我使用调试器进行了跟踪,因此它在控制台上未显示错误,但是redux开发工具显示了状态,并且错误为未授权
这来自有效负载,这是因为jwt令牌不是在配置文件路由上发送的。
// error reducer
import {GET_ERRORS} from '../actions/types';
const initialState = {}
export default (state = initialState, action) => {
switch(action.type){
case GET_ERRORS:
debugger
return action.payload;
debugger
default:
return state
}
};
// profile action
// Create Profile
export const createProfile = (profileData, history) => dispatch => {
axios
.post('/api/profiles', profileData)
// .post('http://localhost:3001/api/profiles', profileData)
.then(res => history.push('/dashboard'))
.catch(err =>
dispatch({
type: GET_ERRORS,
payload:err.response.data,
})
);
};
// Login Auth and token
export const loginUser = userData => dispatch => {
axios
.post('/api/users/login', userData)
.then(res => {
// save token to localstorage
const {token} = res.data
// set token to ls
localStorage.setItem('jwtToken',token);
// link token to head
saveTokenToHead(token)
// extract user details from token using jwt decode
const extracted = jwt_decode(token)
// set the token to current user
dispatch(setCurrentUser(extracted))
})