Google Sign-In Intermittently works












1















I've got a page that's using Google Sign-In. 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". 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:
This is good.



Sometimes it comes up as just this:
This is bad.



My Bootstrap 4 + JS code is as follows:



<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>









share|improve this question



























    1















    I've got a page that's using Google Sign-In. 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". 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:
    This is good.



    Sometimes it comes up as just this:
    This is bad.



    My Bootstrap 4 + JS code is as follows:



    <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>









    share|improve this question

























      1












      1








      1








      I've got a page that's using Google Sign-In. 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". 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:
      This is good.



      Sometimes it comes up as just this:
      This is bad.



      My Bootstrap 4 + JS code is as follows:



      <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>









      share|improve this question














      I've got a page that's using Google Sign-In. 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". 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:
      This is good.



      Sometimes it comes up as just this:
      This is bad.



      My Bootstrap 4 + JS code is as follows:



      <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>






      google-signin googlesigninapi googlesigninaccount






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 22:20









      David ByersDavid Byers

      1162218




      1162218
























          1 Answer
          1






          active

          oldest

          votes


















          0














          What triggers 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.






          share|improve this answer
























          • That's part of the problem... there are no errors in the console. I don't believe that it's failing to trigger, but I will try forcing renderButton() to fire again and see if that helps.

            – David Byers
            Dec 4 '18 at 23:01











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421242%2fgoogle-sign-in-intermittently-works%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          What triggers 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.






          share|improve this answer
























          • That's part of the problem... there are no errors in the console. I don't believe that it's failing to trigger, but I will try forcing renderButton() to fire again and see if that helps.

            – David Byers
            Dec 4 '18 at 23:01
















          0














          What triggers 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.






          share|improve this answer
























          • That's part of the problem... there are no errors in the console. I don't believe that it's failing to trigger, but I will try forcing renderButton() to fire again and see if that helps.

            – David Byers
            Dec 4 '18 at 23:01














          0












          0








          0







          What triggers 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.






          share|improve this answer













          What triggers 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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 3 '18 at 11:08









          David GDavid G

          5,13441839




          5,13441839













          • That's part of the problem... there are no errors in the console. I don't believe that it's failing to trigger, but I will try forcing renderButton() to fire again and see if that helps.

            – David Byers
            Dec 4 '18 at 23:01



















          • That's part of the problem... there are no errors in the console. I don't believe that it's failing to trigger, but I will try forcing renderButton() to fire again and see if that helps.

            – David Byers
            Dec 4 '18 at 23:01

















          That's part of the problem... there are no errors in the console. I don't believe that it's failing to trigger, but I will try forcing renderButton() to fire again and see if that helps.

          – David Byers
          Dec 4 '18 at 23:01





          That's part of the problem... there are no errors in the console. I don't believe that it's failing to trigger, but I will try forcing renderButton() to fire again and see if that helps.

          – David Byers
          Dec 4 '18 at 23:01


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421242%2fgoogle-sign-in-intermittently-works%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Create new schema in PostgreSQL using DBeaver

          Deepest pit of an array with Javascript: test on Codility

          Costa Masnaga