Reputation: 18869
I have the following snippet of code:
var myParams = {
'clientid' : 'XXXXX.apps.googleusercontent.com',
'cookiepolicy' : 'single_host_origin',
'callback' : _.bind(function(response){ this._loginGoogleCb(response); }, this),
'scope' : 'https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/plus.profile.emails.read',
'requestvisibleactions' : 'http://schemas.google.com/AddActivity'
};
gapi.auth.signIn(myParams);
The first time I click the button and this code gets executed, there is no problem.
But when I click the button for a second time, the callback (and only the callback) gets executed twice.
Every time I execute this code, the number of requests to the Google server (and the related callback) increases by 1.
I double checked, the calling function itself gets only executed once when repeated.
The button click itself is not the problem.
Any idea what might be the problem?
Upvotes: 3
Views: 1286
Reputation: 20230
As can be seen from this article, there are three different status methods:
in the authorization object:
{
"id_token": string,
"access_token": string,
"expires_in": string,
"error": string
"status": { /* object */
"google_logged_in" : boolean,
"signed_in" : boolean,
"method" : string /* null, PROMPT, or AUTO */
}
}
What is happening is that when you are logging-in for the first time just one of these status methods are being triggered ("PROMPT"), but when you press the button again two status methods are triggered ("PROMPT" and "AUTO").
Example "signinCallback" code for dealing with these status methods can be found here.
Also if you are calling underscore's bind funtion multiple times, then the bound function will also be called multiple times. Hence the reason why you are seeing "the number of requests to the Google server (and the related callback) increases with 1." I'd suggest encapsulating this call to bind within another function and include a guard condition to stop this being called multiple times.
Upvotes: 2