3

I am trying to ensure that user will always be sent to login page if they are not currently logged in. I'm using Redux to store the current user id, so that's not the problem. The main problem is that no matter what checks I put in the router file, the app shows all the pages when I navigate to them. Any help would be greatly appreciated.

 <Router sceneStyle={{ paddingTop: 65 }}>
  <Scene 
    key="splash" 
    component={Splash} 
    title="App" 
    timeout={500} 
    nextScene={'main'} 
    initial 
  />

  <Scene key="auth" >
    <Scene key="login" component={LoginForm} title="Please Login" />
  </Scene>

  <Scene key="profile">
    <Scene key="profilePage" component={ProfilePage} title="My Profile" />
  </Scene>

  <Scene key="main" >
    <Scene
      key="subscribedList"
      component={SubscribedList}
      title="Choose A List"
    />
    <Scene
      key="itemsList"
      component={ItemsList}
      onBack={() => Actions.subscribedList()}
    />
    <Scene
      key="createList"
      component={CreateList}
      title="Create A List"
    />
    <Scene
      key="createItem"
      component={CreateItem}
      title="Create Item"
    />
    <Scene
      key="compareItem"
      component={CompareItem}
      title="Found Item"
    />
  </Scene>
</Router>
dsvorc41
  • 45
  • 1
  • 7

2 Answers2

1

I am using Switch as in router flux docs:
https://github.com/aksonov/react-native-router-flux/blob/master/docs/OTHER_INFO.md

  handlePressPurchases = () => {
     Actions.account({section: 'purchases'})
   }



    import { connect } from 'react-redux'

    <Scene
             key="account"
             component={connect(state=>({isAuth: state.login.username != null }))(Switch)}
             tabs={true} 
             unmountScenes
             selector={props=> !props.isAuth ? "login_account" : props.section }
         >
             <Scene key="login_account" component={LoginScreen} title="Login"/>
             <Scene key='purchases' component={Purchases} title='Purchases'  navBar={AppNavBar} />
             <Scene key='balance' component={Balance} title='Balance'  navBar={AppNavBar} />
    </Scene>

Second alternative was to use Actions.login() redirect in each scene component based on authState.

Danny
  • 415
  • 4
  • 6
0

I would suggest you to look into redux middleware, eg. Sample implementation on github

nehvaleem
  • 117
  • 8