Make Axios ready to receive the server responses
This commit is contained in:
parent
4108e3a2ca
commit
408c2fca75
@ -54,7 +54,7 @@ export function loginUser(username, password) {
|
||||
password: password,
|
||||
},
|
||||
).then(response => {
|
||||
if (response.data && response.data.type && response.data.type === 'error')
|
||||
if (response.data.status === 'error')
|
||||
{
|
||||
dispatch({
|
||||
type: ADD_ERROR,
|
||||
@ -65,7 +65,7 @@ export function loginUser(username, password) {
|
||||
}
|
||||
dispatch({
|
||||
type: USER_LOGIN_FULFILLED,
|
||||
payload: response,
|
||||
payload: response.data,
|
||||
})
|
||||
}).catch(error => {
|
||||
console.log(error)
|
||||
@ -86,7 +86,7 @@ export function fetchMovies() {
|
||||
headers: { 'Authorization': header },
|
||||
})
|
||||
.then(response => {
|
||||
if (response.data.type && response.data.type === 'error')
|
||||
if (response.data.status === 'error')
|
||||
{
|
||||
dispatch({
|
||||
type: ADD_ERROR,
|
||||
@ -94,11 +94,12 @@ export function fetchMovies() {
|
||||
message: response.data.message,
|
||||
}
|
||||
})
|
||||
} else {
|
||||
dispatch({
|
||||
type: MOVIE_LIST_FETCH_FULFILLED,
|
||||
payload: response.data,
|
||||
})
|
||||
}
|
||||
dispatch({
|
||||
type: MOVIE_LIST_FETCH_FULFILLED,
|
||||
payload: response,
|
||||
})
|
||||
})
|
||||
.catch(error => {
|
||||
// Unauthorized
|
||||
|
@ -9,7 +9,7 @@ export default function movieStore(state = defaultState, action) {
|
||||
switch (action.type) {
|
||||
case MOVIE_LIST_FETCH_FULFILLED:
|
||||
return Object.assign({}, state, {
|
||||
movies: action.payload.data.Data.movies,
|
||||
movies: action.payload.data,
|
||||
})
|
||||
case MOVIE_LIST_FETCH_PENDING:
|
||||
return state
|
||||
|
@ -15,11 +15,10 @@ export default function userStore(state = defaultState, action) {
|
||||
userLoading: true,
|
||||
})
|
||||
case USER_LOGIN_FULFILLED:
|
||||
const data = action.payload.data;
|
||||
if (data && data.type === "error") {
|
||||
if (action.payload.status === "error") {
|
||||
return logoutUser(state)
|
||||
}
|
||||
return updateFromToken(state, data.token)
|
||||
return updateFromToken(state, action.payload.data.token)
|
||||
case IS_USER_LOGGED_IN:
|
||||
let localToken = localStorage.getItem('token');
|
||||
if (!localToken || localToken === "") {
|
||||
|
Loading…
x
Reference in New Issue
Block a user