I'm using Google Login via JS and it appears my code is getting data twice. I'm not sure why this is occurring.
When I click my "Log In with Google" button, it spits out (console.log(result)) data for the user. THEN a prompt occurs asking me to choose an account of mine (I'm logged into several google accounts). When I click the account I'd like, the code then spits out that user data again.
Why is this occurring? It's a problem because where I spit out the data, I'd like to make a ajax call to verify the user and then redirect them. So in essence, it's trying to do this twice -- which is not cool, what if I don't want to login using the credentials google passes back on the first go around?
(function() {
var po = document.createElement('script');
po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/client:plusone.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(po, s);
})();
function googleLogin() {
var additionalParams = {
'callback': googleCallback
};
gapi.auth.signIn(additionalParams);
}
function googleCallback(authResult) {
if (authResult['status']['signed_in']) {
gapi.client.load('oauth2', 'v2', function() {
gapi.client.oauth2.userinfo.get().execute(function(resp) {
console.log(resp);
})
});
} else {
console.log('Sign-in state: ' + authResult['error']);
}
}
Update: If I sign out of all my Google accounts (with the exception of one and only one), the call to google is still duplicated. This time it logs in and I see console.log() outputting data twice. Access tokens are identical.
Update 2: console.log(resp) is outputting twice
Update 3: Just more clarification:
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…