Monday, 29 May 2017

Redirect user after login with react-navigation and redux

I have a login component in React Native.

I use use react-navigation and redux to store isLoggedIn in my authReducer.

I want the user to be sent away from the login component if he/she is logged in. So it should never be possible to see the login page if you are already logged in.

I guess I have to setup the navReducer as they do at https://github.com/react-community/react-navigation/blob/master/examples/ReduxExample/src/reducers/index.js. I am just not sure what is meant by

// Start with two routes: The Main screen, with the Login screen on top.
const firstAction = AppNavigator.router.getActionForPathAndParams('Main');
const tempNavState = AppNavigator.router.getStateForAction(firstAction);
const secondAction = AppNavigator.router.getActionForPathAndParams('Login');
const initialNavState = AppNavigator.router.getStateForAction(
  secondAction,
  tempNavState
);

How would you normally protect some routes and force the user to log in and after he/she is successfully logged in, he/she should be sent to another route?



via Jamgreen

No comments:

Post a Comment