import firebase , { firebaseAuth } from 'src/firebase' ; import createReducer from 'src/store/utils/createReducer' ; import emailReducer from './email/reducer' ; import facebookReducer from './facebook/reducer' ; import googleReducer from './google/reducer' ; import phoneReducer from './phone/reducer' ; import { AuthState , LOGOUT , OBSERVE_USER } from './types' ; const initialState = { loading : false , checkEmail : undefined , error : undefined , user : firebaseAuth . currentUser , confirmationResult : undefined , observerReceivedFirstUpdate : false , } ; export default createReducer < AuthState > ( { ... facebookReducer , ... phoneReducer , ... emailReducer , ... googleReducer , [ OBSERVE_USER . SUBSCRIBE ] : ( state ) => { state . loading = true ; } , [ OBSERVE_USER . UPDATED ] : ( state , { payload } ) => { state . user = payload ; state . loading = false ; state . observerReceivedFirstUpdate = true ; } , [ LOGOUT . PENDING ] : ( state ) => { state . loading = true ; } , [ LOGOUT . REJECTED ] : ( state , { payload } ) => { state . loading = false ; state . error = payload ; } , [ LOGOUT . COMPLETED ] : ( state ) => { state . loading = false ; state . user = undefined ; state . confirmationResult = undefined ; } , } , initialState ) ;