Google+ Sign-In with JavaScript callback issue

前端 未结 6 2828
轮回少年
轮回少年 2021-02-08 13:01

I am working on a function which allows users to sign in on my website with their Google account.

My code is based on the Google documentation (others signIn() options a

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-08 13:38

    Try to register first call in some local variable and then process it

    This quick solution helps me:

    function login() {
      var initializedGoogleCallback = false
      gapi.auth.signIn({
        'callback': function (authResult) {
           if (!initializedGoogleCallback) {
             // after first call other will be ignored
             initializedGoogleCallback = true;
             if (authResult['status']['signed_in']) {
               console.log('Okay');
             } else {
               console.log('Error');
             }
           }
        }
      });
    }
    

    also you can add following code before call gapi.auth.signIn

    window.removeEventListener('load')
    

提交回复
热议问题