Skip to content

Commit

Permalink
removed unused cases and added error on default
Browse files Browse the repository at this point in the history
  • Loading branch information
bushblade committed Jan 31, 2020
1 parent e54fc48 commit 7f52979
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions client/src/reducers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ import {
LOGIN_FAIL,
LOGOUT,
ACCOUNT_DELETED
} from '../actions/types';
} from '../actions/types'

const initialState = {
token: localStorage.getItem('token'),
isAuthenticated: null,
loading: true,
user: null
};
}

export default function(state = initialState, action) {
const { type, payload } = action;
const { type, payload } = action

switch (type) {
case USER_LOADED:
Expand All @@ -26,29 +26,25 @@ export default function(state = initialState, action) {
isAuthenticated: true,
loading: false,
user: payload
};
}
case REGISTER_SUCCESS:
case LOGIN_SUCCESS:
localStorage.setItem('token', payload.token);
localStorage.setItem('token', payload.token)
return {
...state,
...payload,
isAuthenticated: true,
loading: false
};
case REGISTER_FAIL:
case AUTH_ERROR:
case LOGIN_FAIL:
case LOGOUT:
}
case ACCOUNT_DELETED:
localStorage.removeItem('token');
localStorage.removeItem('token')
return {
...state,
token: null,
isAuthenticated: false,
loading: false
};
}
default:
return state;
throw Error(`Unsupported type: ${action.type}`)
}
}

0 comments on commit 7f52979

Please sign in to comment.