Google+ Sign-In with JavaScript callback issue

前端 未结 6 2794
轮回少年
轮回少年 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:29

    That is the intentional plan for page level config! It being present in the page causes the callback to fire when the Javascript is finished loading. What you should do is prepare for that in your code.

    Don't show the sign in button until you have received a callback - if authResult['status']['signed_in'] == true, then treat the user as signed in (setup a session etc, whatever you would normally do). If it is false, then display the button.

    function signinCallback(authResult) {
      if (authResult['status']['signed_in']) {
        document.getElementById('signinButton').setAttribute('style', 'display: none');
        // Do sign in stuff here!
      } else {
        document.getElementById('signinButton').setAttribute('style', 'display: block');
      }
    }
    

    I would avoid using approval prompt force if you can!

提交回复
热议问题