Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling data-onsuccess method for Google sign-in

I am trying to integrate Google Sign In into my web app.

My page has the Google button:

ModalDialogue.cshtml:

<a class="google g-signin2" data-onsuccess="onSignIn">Sign up with Google+</a>

I'm trying to trigger that method in my js:

ModalDialogue.js:

      function onSignIn(googleUser) {
        var profile = googleUser.getBasicProfile();
        console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
        console.log('Name: ' + profile.getName());
        console.log('Image URL: ' + profile.getImageUrl());
        console.log('Email: ' + profile.getEmail());
      }

I know that

a] the JavaScript is in the scope of the page, since my other functions - for opening and closing the dialogue - DO work.

b] the button is communicating with Google, since clicking on it DOES open the 'sign-in with Google' dialogue - and then once done - changes the button to 'Sign In' afterward.

How do I trigger the onSignIn method? Or at least how do I determine whether onsuccess is being triggered?

like image 643
Dave Collins Avatar asked Jul 30 '15 20:07

Dave Collins


2 Answers

Oh. My bad. I hadn't noticed I had the method wrapped in a closure. Needs to be global.

like image 90
DaveC426913 Avatar answered Sep 18 '22 17:09

DaveC426913


For people who come to this page in the future, I had to move the function definition above the button tag. Seems like it shouldn't matter, as data-onsuccess is simply a string. It didn't throw any error messages, unfortunately.

like image 23
bradlis7 Avatar answered Sep 19 '22 17:09

bradlis7