27 lines
584 B
JavaScript
27 lines
584 B
JavaScript
import { Record } from 'immutable';
|
|
import { INIT_AUTH, SIGN_IN_SUCCESS, SIGN_OUT_SUCCESS } from './action-types';
|
|
|
|
|
|
export const AuthState = new Record({
|
|
authenticated: false,
|
|
id: null
|
|
});
|
|
|
|
|
|
export function authReducer(state = new AuthState(), {payload, type}) {
|
|
switch (type) {
|
|
case INIT_AUTH:
|
|
case SIGN_IN_SUCCESS:
|
|
return state.merge({
|
|
authenticated: !!payload, //cc:signin#5;toggle 'authenticated' flag
|
|
id: payload ? payload.uid : null
|
|
});
|
|
|
|
case SIGN_OUT_SUCCESS:
|
|
return new AuthState();
|
|
|
|
default:
|
|
return state;
|
|
}
|
|
}
|