Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initiate Google sign in on button click

Hello I am using google api to sign in to my web application . Now Its working fine . But the problem is the sigin is initiated automatically as I go to my log in page . But I do not want that . I want the user to click the signin button first then the process will start .

I am using below button

<div class="g-signin2" data-onsuccess="onSignIn"></div>

and google log in references .

like image 502
Abdullah Al Noman Avatar asked Sep 17 '15 06:09

Abdullah Al Noman


People also ask

How do I create a Google sign in button?

To create a Google Sign-In button with custom settings, add an element to contain the sign-in button to your sign-in page, write a function that calls signin2. render() with your style and scope settings, and include the https://apis.google.com/js/platform.js script with the query string onload=YOUR_RENDER_FUNCTION .

How do I create a Google sign in HTML?

Add Google Sign-In to Your Web App console. log("ID: " + profile. getId()); // Don't send this directly to your server!


1 Answers

Use 'attachClickHandler' to Initiate Google Sign In.

<script src="https://apis.google.com/js/client:platform.js?onload=init" async defer></script>
<script>
   function init() {
        gapi.load('auth2', function() {
            auth2 = gapi.auth2.init({
                client_id: '*************.apps.googleusercontent.com',
                cookiepolicy: 'single_host_origin',
                scope: 'profile email'
            });
            element = document.getElementById('glogin');
            auth2.attachClickHandler(element, {}, onSignUp, onFailure);
        });
    }
    function onSignUp(googleUser) {
      var profile = googleUser.getBasicProfile();
    }
</script>
like image 157
parth kabariya Avatar answered Sep 22 '22 19:09

parth kabariya