Google Sign in for my Login Page, Not Working

34 Views Asked by At

It seems like the error is occurring during the sign-in process, specifically when the popup is being closed by the user. The error message popup_closed_by_user is expected when the user closes the authentication popup before completing the sign-in.

While login, I am getting the error:

Error during sign-in: popup_closed_by_user

Tell me what to change, I have no idea about these Gooogle API - Default Login code are giving some errors.

<html lang="en">
<head>
  <script src="https://apis.google.com/js/platform.js?onload=renderApp" async defer></script>
</head>

<body>
  <div class="g-signin2" id="customBtn">Sign in with Google+</div>
  <script>
    function onSignIn(googleUser) {
      // Useful data for your client-side scripts:
      var profile = googleUser.getBasicProfile();
      console.log("ID: " + profile.getId()); // Don't send this directly to your server!
      console.log('Full Name: ' + profile.getName());
      console.log('Given Name: ' + profile.getGivenName());
      console.log('Family Name: ' + profile.getFamilyName());
      console.log("Image URL: " + profile.getImageUrl());
      console.log("Email: " + profile.getEmail());

      // The ID token you need to pass to your backend:
      var id_token = googleUser.getAuthResponse().id_token;
      console.log("ID Token: " + id_token);
    };
  </script>

  <script>

    var renderApp = function () {
      //  GOOGLE_CLIENT_ID  should be create from  https://developers.google.com/identity/sign-in/web/devconsole-project   
      gapi.load('auth2', function () {
        auth2 = gapi.auth2.init({
          client_id: 'ClientId.apps.googleusercontent.com',
          cookiepolicy: 'single_host_origin',
        });
        attachSignin('customBtn'); //Function called  for click 
      });
    };

    function attachSignin(customBtn) {
      auth2.attachClickHandler(customBtn, {}, onSignIn, function (error) {
        console.log("Error during sign-in:", error);
      });
    }

  </script>
</body>

</html>
0

There are 0 best solutions below