inProgress-team / react-native-meteor

Meteor Reactivity for your React Native application :)
MIT License
693 stars 210 forks source link

Meteor.user() return null after user logged in #110

Closed ahmay98 closed 8 years ago

ahmay98 commented 8 years ago

Hey there,

I'm using the following -- "react-native": "0.29.1", "react-native-meteor": "^1.0.0-rc14", "react-native-router-flux": "^3.31.1"

My starting point is a pretty simple, when the app first loads, connect; if there's no Meteor.user(), goto 'login' scene, otherwise goto 'home'.

Then from the 'login' scene, there's the call to Meteor.loginWithPassword. If/when succeeded, hit 'Actions.home()'.

The problem I have is, once the user successfully logged in -- validated by logging 'Meteor.user()' to console, and then the router tries to go Actions.home(), somewhere in between Meteor.user() becomes 'null' again.

Thoughts?

thanks, --may

Code -- (js/index.js)

function composer() {
    console.log('=========== composer called');
    return {
        connected: Meteor.status().connected,
        user: Meteor.user()
    }
}

function selector (data, props) {
    console.log('=========== selector called');
    console.log('selector data', data);

    const user = data.user;
    if (!user) {
        return 'public';
    } else {
        return 'protected';
    }
}

const scenes = Actions.create(
    <Scene key="modal" component={Modal} >
        <Scene key="root" component={createContainer(composer, Switch)} selector={selector}>
            <Scene key="public" hideNavBar>
                <Scene key="login" component={Login} hideNavBar title="Login" />
                <Scene key="signUp" component={BlankPage} hideNavBar />
                <Scene key="needHelp" component={BlankPage} hideNavBar />
                <Scene key="walkThrough" component={WalkThrough} hideNavBar />
            </Scene>

            <Scene key="protected">
                <Scene key="home" component={BlankPage} title="Home" type={ActionConst.REPLACE} />
            </Scene>
        </Scene>
    </Scene>
);

@connectMeteor
export default class App extends Component {

    componentWillMount () {
        connect();
    }

    render() {
        return (
            <Router scenes={scenes} />
        );
    }
}

(fragment from login.js)

    loginWithPassword () {
        Meteor.loginWithPassword (this.state.login, this.state.password, function (err, result) {
            if (err) {
                alert(err);
            } else {
                console.log('user logged in', Meteor.user());
                Actions.home();
            }
        });
    }

Console log --

2016-07-22 17:11:03.755 [info][tid:com.facebook.react.JavaScript] =========== composer called
2016-07-22 17:11:03.756 [info][tid:com.facebook.react.JavaScript] =========== selector called
2016-07-22 17:11:03.757 [info][tid:com.facebook.react.JavaScript] 'selector data', { navigationState: 
   { key: '0_root',
     name: 'root',
     sceneKey: 'root',
     parent: 'modal',
     type: 'REACT_NATIVE_ROUTER_FLUX_PUSH',
     selector: [Function: selector],
     component: { [Function: Constructor] displayName: 'MeteorDataContainer' },
     children: 
      [ { key: '0_public',
          name: 'public',
          sceneKey: 'public',
          parent: 'root',
          type: 'REACT_NATIVE_ROUTER_FLUX_PUSH',
          hideNavBar: true,
          children: 
           [ { key: '0_login',
               name: 'login',
               sceneKey: 'login',
               parent: 'public',
               type: 'REACT_NATIVE_ROUTER_FLUX_PUSH',
               hideNavBar: true,
               title: 'Login',
               component: 
                { [Function: Login]
                  childContextTypes: { theme: { [Function: checkType] isRequired: [Function: checkType] } } },
               index: 0 } ],
          index: 0 } ],
     index: 0 },
  name: 'root',
  sceneKey: 'root',
  parent: 'modal',
  type: 'REACT_NATIVE_ROUTER_FLUX_PUSH',
  selector: [Function: selector],
  component: { [Function: Constructor] displayName: 'MeteorDataContainer' },
  children: 
   [ { key: '0_public',
       name: 'public',
       sceneKey: 'public',
       parent: 'root',
       type: 'REACT_NATIVE_ROUTER_FLUX_PUSH',
       hideNavBar: true,
       children: 
        [ { key: '0_login',
            name: 'login',
            sceneKey: 'login',
            parent: 'public',
            type: 'REACT_NATIVE_ROUTER_FLUX_PUSH',
            hideNavBar: true,
            title: 'Login',
            component: 
             { [Function: Login]
               childContextTypes: { theme: { [Function: checkType] isRequired: [Function: checkType] } } },
            index: 0 } ],
       index: 0 } ],
  index: 0,
  onNavigate: [Function: handleNavigation],
  connected: true,
  user: null }
2016-07-22 17:11:03.877 [info][tid:com.facebook.react.JavaScript] **'user logged in', { _id: 'yBq3rHMJTLQjmccNC',
  emails: [ { address: 'may.huang@exp-labs.com', verified: false } ],
  profile: { firstName: 'Amy', lastName: 'Wang' },
  _version: 1 }**
2016-07-22 17:11:03.888 [info][tid:com.facebook.react.JavaScript] =========== composer called
2016-07-22 17:11:03.889 [info][tid:com.facebook.react.JavaScript] =========== selector called
2016-07-22 17:11:03.890 [info][tid:com.facebook.react.JavaScript] 'selector data', { navigationState: 
   { key: '0_root',
     name: 'root',
     sceneKey: 'root',
     parent: 'modal',
     type: 'REACT_NATIVE_ROUTER_FLUX_PUSH',
     selector: [Function: selector],
     component: { [Function: Constructor] displayName: 'MeteorDataContainer' },
     children: 
      [ { key: '0_public',
          name: 'public',
          sceneKey: 'public',
          parent: 'root',
          type: 'REACT_NATIVE_ROUTER_FLUX_PUSH',
          hideNavBar: true,
          children: 
           [ { key: '0_login',
               name: 'login',
               sceneKey: 'login',
               parent: 'public',
               type: 'REACT_NATIVE_ROUTER_FLUX_PUSH',
               hideNavBar: true,
               title: 'Login',
               component: 
                { [Function: Login]
                  childContextTypes: { theme: { [Function: checkType] isRequired: [Function: checkType] } } },
               index: 0 } ],
          index: 0 } ],
     index: 0 },
  name: 'root',
  sceneKey: 'root',
  parent: 'modal',
  type: 'REACT_NATIVE_ROUTER_FLUX_PUSH',
  selector: [Function: selector],
  component: { [Function: Constructor] displayName: 'MeteorDataContainer' },
  children: 
   [ { key: '0_public',
       name: 'public',
       sceneKey: 'public',
       parent: 'root',
       type: 'REACT_NATIVE_ROUTER_FLUX_PUSH',
       hideNavBar: true,
       children: 
        [ { key: '0_login',
            name: 'login',
            sceneKey: 'login',
            parent: 'public',
            type: 'REACT_NATIVE_ROUTER_FLUX_PUSH',
            hideNavBar: true,
            title: 'Login',
            component: 
             { [Function: Login]
               childContextTypes: { theme: { [Function: checkType] isRequired: [Function: checkType] } } },
            index: 0 } ],
       index: 0 } ],
  index: 0,
  onNavigate: [Function: handleNavigation],
  connected: true,
  **user: null** }
Mokto commented 8 years ago

No idea right now.

We need a reproduction repo please ;)