S
S
Shane Matte2016-11-29 11:36:27
JavaScript
Shane Matte, 2016-11-29 11:36:27

Why doesn't routing work in react native router flux during authorization?

Hello. I do authorization in react native. I am using react native router flux routing module. Here is the initial component.

export default class authreactnative extends Component {

  state = {
      loggedIn:false,
  }

  componentWillMount = () => {

    firebaseApp.auth().onAuthStateChanged((user) => {

        this.setState({
          loggedIn:!!user,
        });

    });

  }
  render() {

    const { loggedIn } = this.state;
    const rootSelector = () => loggedIn ? 'home' : 'login';

    return (
      <Router>
        <Scene key="root" tabs={true} selector={rootSelector}>
          <Scene key="login" >
            <Scene key="authuser" initial={true} component={Auth} title="auth"/>
          </Scene>
          <Scene key="home">
            <Scene key="appuser" initial={true} component={App} title="app"/>
          </Scene>
        </Scene>
      </Router>
    );

  }
}

The login scene always fires, although I manually changed the state, it always opens login. After successful authorization, there are no errors, but it does not throw me on the home scene I need. The console after authorization writes
Key authuser is already defined!
Key login is already defined!
Key appuser is already defined!
Key home is already defined!
Key root is already defined!

What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniel Skripnik, 2017-03-09
@blackPeanut

As far as I remember, react-native-router-flux always renders the first scene, which is specified in the root component. Perhaps you should try to move the authorization to a separate component from where to make the transition to the desired scene upon successful authorization.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question