34 lines
716 B
JavaScript
34 lines
716 B
JavaScript
import { LOGIN_SUCCESS, LOGOUT_SUCCESS } from '../actions/auth.actions';
|
|
|
|
const initialState = {
|
|
isLoggedIn: false,
|
|
user: null,
|
|
};
|
|
|
|
export function sessionReducer(state = initialState, action) {
|
|
switch(action.type) {
|
|
case LOGIN_SUCCESS:
|
|
return handleLoginSuccess(state, action);
|
|
case LOGOUT_SUCCESS:
|
|
return handleLogoutSuccess(state, action);
|
|
}
|
|
return state;
|
|
}
|
|
|
|
function handleLoginSuccess(state, action) {
|
|
return {
|
|
...state,
|
|
isLoggedIn: true,
|
|
user: {
|
|
username: action.username,
|
|
},
|
|
};
|
|
}
|
|
|
|
function handleLogoutSuccess(state, action) {
|
|
return {
|
|
...state,
|
|
isLoggedIn: false,
|
|
user: null,
|
|
};
|
|
} |