Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const defaultState = {
- appName: 'Conduit',
- token: null
- };
- export default (state = defaultState, action) => {
- switch (action.type) {
- // APP_LOAD => set token, user, loaded state
- case 'APP_LOAD':
- return {
- ...state,
- token: action.token || null,
- appLoaded: true,
- currentUser: action.payload ? action.payload.user : null,
- };
- // REDIRECT ->< remove redirectTO from state
- case 'REDIRECT':
- return {...state, redirectTo: null};
- // LOGIN => redirect to home, put token and user into state
- case 'LOGIN':
- return {
- ...state,
- redirectTo: action.error ? null : '/',
- token: action.error ? null : action.payload.user.token,
- currentUser: action.error ? null : action.payload.user,
- };
- default:
- return state;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment