0

I am trying to navigate to Main Screen and code still work fine if the JS DEBUGGER is ON(running) but the problem is when i try to run my application when JS DEBUGGER is OFF(disable) and try to login at that time "yield put(NavigationActions.navigate({ routeName: 'Main' }));" this piece code is not redirecting to Main screen.

Given below is my code:

import { NavigationActions } from 'react-navigation';
import { call, put, takeEvery, take } from 'redux-saga/effects';
import { getFirebase } from 'react-redux-firebase';

export function* watchLoginAsync({email, password}) {
  try {
    const response = yield getFirebase().login({email,password});
    if (response.uid) {
      // dispatchToMain();
      yield put(NavigationActions.navigate({ routeName: 'Main' }));
      // yield put({type: LOGIN_SUCCESS });
    } else {
      yield put({type: LOGIN_FAIL, error: 'Something went wrong seriously!!'});
    }
  } catch(err => console.log(err))
}

export default function* watchLogin() {
  yield takeEvery(LOGIN_REQUESTING, watchLoginAsync);
}

And this the store.js file(where i have integrated redux-saga with react-redux-firebase)

const sagaMiddleware = createSagaMiddleware();
const middleware = [ sagaMiddleware ];

const firebaseConfig = {
 apiKey: '******',
 authDomain: '****',
 databaseURL: '****',
 projectId: '****',
 storageBucket: '****',
 messagingSenderId: '****',
};

const reduxFirebaseConfig = {
 userProfile: 'users',
 enableLogging: true,
 enableRedirectHandling: false,
};

// Add redux Firebase to compose
const createStoreWithFirebase = compose(
 reactReduxFirebase(fbConfig, reduxFirebaseConfig),
 applyMiddleware(...middleware)
)(createStore);

// Add Firebase to reducers
const rootReducer = combineReducers({
 firebase: firebaseStateReducer,
 ......
});

// Create store with reducers and initial state
const initialState = {}
export default createStoreWithFirebase(rootReducer, initialState);

// when calling saga, pass getFirebase
sagaMiddleware.run(Sagas, getFirebase)

NOTE: code is totally working fine if JS DEBUGGER IS ON iOS simulator while app is running.

  • are u using loggerMiddleware?? .. i had some issues in emulator .. u need to click the screen to trigger actions in emulator if redux logger and debugging is turn on .. – Victor Nov 14 '17 at 04:43
  • no i am not using any logger Middleware but see can you look at my redux-saga store.js file i think this is happening because something is wrong in 'reduxFirebaseConfig' – ankit_morker Nov 14 '17 at 05:24

1 Answers1

0

NOTE: code is totally working fine if JS DEBUGGER IS ON iOS simulator while app is running.

In general debugging mode differs from normal execution by timings - e.g. in debug mode some asynchronous action is performed while you are watching values on breakpoint, and also execution in debug mode is much slower due interception ES262-engine actions. You can try to debug more verbosely by using console.log instructions.

Also, supplied source code

const createStoreWithFirebase = compose(
 reactReduxFirebase(fbConfig, reduxFirebaseConfig),
 applyMiddleware(...middleware)
)(createStore);

does not include mandatory saga initial invoke operation, like sagaMiddleware.run(rootSaga), what's why maybe nothing is executed.

In original documentation it's present: https://github.com/prescottprue/react-redux-firebase/blob/master/docs/recipes/redux-saga.md

Vladislav Ihost
  • 2,127
  • 11
  • 26