По-видимому, я получаю сообщения об ошибках "Unauthorized" и "Unauthorized" 1: {type: "GET_ERRORS", payload: я отследил это с помощью отладчика, поэтому он не отображает ошибки на консоли, но инструменты избыточного разработчика показывают состояние иошибки как несанкционированные
это происходит из полезной нагрузки, и это из-за того, что токен 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))
})