client/src/reducers/authReducer.js
changeset 90 990f2c928b15
parent 89 06f609adfbf8
child 91 143ff08ec2cc
equal deleted inserted replaced
89:06f609adfbf8 90:990f2c928b15
     6   switch (action.type) {
     6   switch (action.type) {
     7     case types.AUTH_DEAUTHENTICATE:
     7     case types.AUTH_DEAUTHENTICATE:
     8     case types.AUTH_LOGOUT:
     8     case types.AUTH_LOGOUT:
     9       return false;
     9       return false;
    10     case types.AUTH_LOGIN_SUCCESS:
    10     case types.AUTH_LOGIN_SUCCESS:
    11     case types.AUTH_REGISTER_SUCCESS:
       
    12       return true;
    11       return true;
    13     default:
    12     default:
    14       return state;
    13       return state;
    15   }
    14   }
    16 }
    15 }
    19   switch (action.type) {
    18   switch (action.type) {
    20     case types.AUTH_DEAUTHENTICATE:
    19     case types.AUTH_DEAUTHENTICATE:
    21     case types.AUTH_LOGOUT:
    20     case types.AUTH_LOGOUT:
    22       return null;
    21       return null;
    23     case types.AUTH_LOGIN_SUCCESS:
    22     case types.AUTH_LOGIN_SUCCESS:
    24     case types.AUTH_REGISTER_SUCCESS:
       
    25       return new UserRecord(action.user);
    23       return new UserRecord(action.user);
    26     case types.USER_UPDATE_SETTINGS:
    24     case types.USER_UPDATE_SETTINGS:
    27       return state.merge({
    25       return state.merge({
    28         first_name: action.firstname,
    26         first_name: action.firstname,
    29         last_name: action.lastname
    27         last_name: action.lastname
    47 
    45 
    48 const loginState = Immutable.Map({
    46 const loginState = Immutable.Map({
    49   loading: false,
    47   loading: false,
    50   success: false,
    48   success: false,
    51   error: false,
    49   error: false,
       
    50   errorMessages: Immutable.Map({})
    52 });
    51 });
    53 
    52 
    54 export const login = (state = loginState, action) => {
    53 export const login = (state = loginState, action) => {
    55   switch (action.type) {
    54   switch (action.type) {
    56     case types.AUTH_LOGIN_REQUEST:
    55     case types.AUTH_LOGIN_REQUEST:
    63     case types.AUTH_LOGIN_ERROR:
    62     case types.AUTH_LOGIN_ERROR:
    64       return Immutable.Map({
    63       return Immutable.Map({
    65         loading: false,
    64         loading: false,
    66         success: action.type === types.AUTH_LOGIN_SUCCESS,
    65         success: action.type === types.AUTH_LOGIN_SUCCESS,
    67         error: action.type === types.AUTH_LOGIN_ERROR,
    66         error: action.type === types.AUTH_LOGIN_ERROR,
       
    67         errorMessages: action.type === types.AUTH_LOGIN_ERROR ? Immutable.Map(action.error) : Immutable.Map({})
    68       })
    68       })
    69     default:
    69     default:
    70       return state
    70       return state
    71   }
    71   }
    72 }
    72 }
    84       return Immutable.Map({
    84       return Immutable.Map({
    85         loading: true,
    85         loading: true,
    86         success: false,
    86         success: false,
    87         error: false,
    87         error: false,
    88       })
    88       })
    89     case types.AUTH_REGISTER_SUCCESS:
    89     case types.AUTH_LOGIN_SUCCESS:
    90     case types.AUTH_REGISTER_ERROR:
    90     case types.AUTH_REGISTER_ERROR:
    91       return Immutable.Map({
    91       return Immutable.Map({
    92         loading: false,
    92         loading: false,
    93         success: action.type === types.AUTH_REGISTER_SUCCESS,
    93         success: action.type === types.AUTH_LOGIN_SUCCESS,
    94         error: action.type === types.AUTH_REGISTER_ERROR,
    94         error: action.type === types.AUTH_REGISTER_ERROR,
    95         errorMessages: action.type === types.AUTH_REGISTER_ERROR ? Immutable.Map(action.error) : Immutable.Map({})
    95         errorMessages: action.type === types.AUTH_REGISTER_ERROR ? Immutable.Map(action.error) : Immutable.Map({})
    96       })
    96       })
    97     default:
    97     default:
    98       return state
    98       return state