React-native-router-flux and react-native-meteor and Logins


#1

I’m having some trouble getting the router to not send me to the login screen after I’m already logged in when I reload the JS or even just go back to the home screen and reopen the app. I have console.log that show that I’m logged in, but my screen doesn’t re-render.

I thought setting initial={!isLoggedIn} on my Login scene would work but it doesn’t seem to.

import React, { Text, View } from 'react-native';
import {Scene, Reducer, Router, Switch, TabBar, Modal, Schema, Actions} from 'react-native-router-flux'
import Meteor, { connectMeteor } from 'react-native-meteor';
import connect from './connect';

import Login from './Login';
import Teams from './modules/teams/containers/Teams';
import Convos from './modules/convos/containers/Convos';
import Chat from './modules/chat/containers/Chat';

@connectMeteor
class App extends React.Component {
  constructor(props) {
    super(props);
    this.data = {};
  }

  componentWillMount() {
    connect();
  }

  getMeteorData() {
    console.log(`----index.getMeteorData----`);
    console.log(`userId ${Meteor.userId()}`);
    console.log(Meteor.status());
    return {
      isLoggedIn: Meteor.userId() ? true : false,
    }
  }

  render() {
    const { isLoggedIn } = this.data;
    console.log(`isLoggedIn ${isLoggedIn}`);
    return (
      <Router createReducer={reducerCreate}>
        <Scene key="root">
          <Scene key="teams" component={Teams} title="Teams" />
          <Scene key="convos" component={Convos} />
          <Scene key="chat" component={Chat} />
          <Scene key="login" component={Login} title="Login" hideNavBar={true} initial={!isLoggedIn} />
        </Scene>
      </Router>
    );
  }
}

const reducerCreate = params => {
    const defaultReducer = Reducer(params);
    return (state, action)=>{
        console.log("ACTION:", action);
        return defaultReducer(state, action);
    }
};

export default App;


#2

Fixed it. For any one interested in the solution refer to this link