mondora / asteroid

An alternative client for a Meteor backend
MIT License
734 stars 101 forks source link

error using loginWithGoogle #34

Closed hexsprite closed 9 years ago

hexsprite commented 9 years ago

Using Chrome.

var ddp = new Asteroid("localhost:3000");

ddp.on('connected', function() {
  console.log("connceted");
  ddp.loginWithGoogle();
});

I get this error:

Uncaught TypeError: Cannot read property 'reactiveQuery' of undefined

From this method:

Asteroid.prototype._getOauthClientId = function (serviceName) {
    var loginConfigCollectionName = "meteor_accounts_loginServiceConfiguration";
    var loginConfigCollection = this.collections[loginConfigCollectionName];
    var service = loginConfigCollection.reactiveQuery({service: serviceName}).result[0];
    return service.clientId || service.consumerKey || service.appId;
};
hexsprite commented 9 years ago

seems to be some kind of timing issue. if I manually execute the code in the console it brings up the login dialog.

pscanf commented 9 years ago

I'm taking a look now. :-)

hexsprite commented 9 years ago

I should probably wait until the subscription for login configuration is .ready. Outside of testing this library it's probably not an issue because login will generally be hooked up to a button or something.

pscanf commented 9 years ago

Ah ok. I think I know. In order to login via oauth, you need the API keys of the oauth service that the server sends you. Those are sent automatically when you connect, when asteroid subscribes to the meteor.loginServiceConfiguration collection (see here). Until the subscription is ready, the collection won't be populated, hence the error.

pscanf commented 9 years ago

Exactly. :-D

pscanf commented 9 years ago

Yes, also because most browsers won't let you open popups unless on response to user events (e.g. clicks). But even for testing, the subscribe method is memoized, so if you call ddp.subscribe("meteor.loginServiceConfiguration") again, it'll return you the same subscription object it returned the first time.