inProgress-team / react-native-meteor

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

loginWithToken #325

Open zyonnetworks opened 6 years ago

zyonnetworks commented 6 years ago

Please add this function to '/node-modules/react-native-meteor/src/user/User.js' so that we can use Meteor.loginWithToken

loginWithToken(value, callback) {
    Data._tokenIdSaved = value;
    if (value !== null) {
      this._startLoggingIn();
      call('login', { resume: value }, (err, result) => {
        this._endLoggingIn();
        this._handleLoginCallback(err, result);
        typeof callback == 'function' && callback(err);
      });
    } else {
      this._endLoggingIn();
    }
  },
ChrisKG32 commented 6 years ago

@zyonnetworks It is not documented, but after some digging I found that Meteor._loginWithToken works just fine. This is only available on the client, so I recommend you make a method that returns Accounts._generateStampedLoginToken() for the token needed.

It would look something like this:
//Server
const stampedToken = Accounts._generateStampedLoginToken();

//Client
//import Meteor from 'react-native-meteor';
Meteor._loginWithToken(stampedToken.token);

Hope that helps!