javascript - Google Sign-in: how to avoid popup dialog if user is already signed in by using listeners? -
right i'm using auth2.attachclickhandler(element, {}, onsuccess, onerror);
. works, if i've signed in, dialog box opens , closes right away rather ugly. there way around using listeners?
i played around example i'm not sure if listening changes current user need, , check of googleuser
seems risky.
auth2 = gapi.auth2.init({client_id: 'xxxxx'}); auth2.currentuser.listen(function (user) { googleuser = user; if (typeof(googleuser.getbasicprofile()) !== 'undefined') document.getelementbyid('signupasgoogle').addeventhandler('click', popuplateform); else auth2.attachclickhandler(document.getelementbyid('signupasgoogle'), {}, onsuccess, onerror);
is there better way? thanks
here did solve same problem!
auth2 = gapi.auth2.init({ clientid: '${clientid}', cookiepolicy: '${cookie_policy}', }); auth2.currentuser.listen(function (googleuser) { if (googleuser.issignedin()) { // login(googleuser) function } else { auth2.attachclickhandler("your button", {}, function (googleuser) { // login(googleuser) function }, function (error) { }); } });
Comments
Post a Comment