react-native-meteor: Meteor.user() is null after Meteor.loginWithPassword()

Hi there,

I met an issue when after doing Meteor.loginWithPassword(), and in the callback did const user = Meteor.user(), it shows user === null.

This happened when my app connected with URL wss://<DOMAIN_NAME>/websocket, but when the app connected with a local host ws://localhost:3000/websocket, it works completely fine, ie it returns the user object as expected.

Am I doing anything wrong with the package or wws stuff?

FYI @adamgins

Regards,

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Comments: 16 (3 by maintainers)

Most upvoted comments

@jeffreyflynt maybe try the new withTracker which replaces createContainer, docs here https://guide.meteor.com/react.html#using-withTracker and put the Meteor.userId() within the withTracker section, something like:

const mapMeteorToProps = (props) => {
  return {
    userId: Meteor.userId(),
  };
};
export default withTracker( mapMeteorToProps )( ClassName );

And in the class (ClassName in this example), use this.props.userId

I had this issue because a few of our users had ids generated by non-meteor apis and had non-meteor _ids. react-native-meteor will log in and issue a token with the non-meteor id but after some debugging it would appear that the collection.findOne returns null give an _id type it isn’t expecting. I have tested with a regular meteor app and login works so it would appear to be an issue with react-native-meteor. #185 Edit: this bug comes from minimongo-cache added a hacky fix to https://github.com/jackkav/minimongo-cache/

@twairball I am doing this way however the container isn’t refreshed after Accounts.createUser. In that case Meteor.user() is still undefined. If I refresh the app then works.