简体   繁体   English

Google登录间歇性地工作

[英]Google Sign-In Intermittently works

I've got a page that's using Google Sign-In. 我有一个使用Google登录的页面。 It's working fine most of the time; 大多数情况下,它运行良好。 however once in a while instead of receiving a "240 pixel wide dark themed button" as defined in the code, I receive a small white button that just says "Sign In". 但是,有时会收到一个小的白色按钮,上面只显示“ Sign In”,而不是收到代码中定义的“ 240像素宽的深色主题按钮”。 When the page only loads the little white button, the sign in doesn't work properly. 当页面仅加载白色小按钮时,登录无法正常工作。 The code isn't dynamic so I don't know why sometimes it renders the white button instead of the blue button. 该代码不是动态的,所以我不知道为什么有时会呈现白色按钮而不是蓝色按钮。

This is what I'm expecting: 这是我所期望的: 很好

Sometimes it comes up as just this: 有时会这样显示: 这不好。

My Bootstrap 4 + JS code is as follows: 我的Bootstrap 4 + JS代码如下:

<div class="container">
    <div class="row justify-content-center col-sm-10 col-md-8 col-lg-6 mx-auto">
        <div id="sign_in_button" class="g-signin2 my-5"></div>

        <div class="w-100 clearfix"></div>

        <div id="sign_out_canvas" class="d-none my-5">
            <button name="sign_out_button" id="sign_out_button" type="button" class="btn btn-light btn-sm">
                <i class="fas fa-sign-out-alt mx-1"></i>
                Sign out
            </button>
            <a href="javascript:void();" onclick="signOut();"></a>
        </div>
    </div>
</div>
</cfoutput>

<script>
    function renderButton() {
        gapi.signin2.render('sign_in_button', {
            'scope': 'profile email',
            'width': 240,
            'height': 50,
            'longtitle': true,
            'theme': 'dark',
            'onsuccess': onSuccess,
            'onfailure': onFailure
        });
    }

    function onSuccess(googleUser) {
        console.log('Google User logged in successfully.');

        $('div#sign_out_canvas').toggleClass('d-none');
        var profile = googleUser.getBasicProfile();

        $.ajax({
            url: '/model/security.cfc',
            method: 'POST',
            data: {
                method: 'signIn',
                'id': profile.getId(),
                'full_name': profile.getName(),
                'given_name': profile.getGivenName(),
                'family_name': profile.getFamilyName(),
                'image_url': profile.getImageUrl(),
                'email': profile.getEmail()
            }
        }).done(function(Data) {
            window.location.replace("/?Action=Home.Home");
        });
    }

    function onFailure(error) {
        console.log(error);
    }
</script>

What triggers renderButton()? 什么触发renderButton()?

It appears it is not triggering every so often, which is why the default (non themed dark blue button) appears. 似乎它并没有经常触发,这就是为什么出现默认值(非主题的深蓝色按钮)的原因。

Because it doesn't trigger, your white button is what stays, and so what you need to work out is why doesn't that trigger? 因为它不会触发,所以白色按键一直存在,所以您需要解决的是为什么不触发? Is it a connectivity problem? 这是连通性问题吗? Is there an error that strikes in some of your other code so that your script never triggers further down? 您的某些其他代码中是否存在错误,以使您的脚本永不再触发?

check your console when the error occurs and you will likely find out what is failing to trigger, and thus why renderButton doesn't. 在发生错误时检查控制台,您很可能会发现触发失败的原因,以及为什么renderButton没有触发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM