You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
'use strict';
|
|
import * as actionTypes from '../actions/auth';
|
|
import Immutable from 'immutable';
|
|
|
|
const initState = {
|
|
user: {},
|
|
isRequesting: false,
|
|
error: null
|
|
};
|
|
|
|
function auth(state = initState, action) {
|
|
const payload = action.payload;
|
|
switch (action.type){
|
|
case actionTypes.INIT_AUTH:
|
|
return Immutable.fromJS(state).set('user', payload.user).toJS();
|
|
case actionTypes.REQUEST_LOGIN:
|
|
return Immutable.fromJS(state).merge({
|
|
isRequesting: true,
|
|
error: null
|
|
}).toJS();
|
|
case actionTypes.LOGIN_SUCCESS:
|
|
return Immutable.fromJS(state).merge({
|
|
isRequesting: false,
|
|
user: payload.user
|
|
}).toJS();
|
|
case actionTypes.LOGIN_ERROR:
|
|
return Immutable.fromJS(state).merge({
|
|
isRequesting: false,
|
|
error: payload.error
|
|
}).toJS();
|
|
case actionTypes.SCREEN_LOGOUT:
|
|
return Immutable.fromJS(state).merge({
|
|
user: null
|
|
}).toJS();
|
|
default:
|
|
return state;
|
|
}
|
|
}
|
|
|
|
export default auth;
|