javascript - HTML PHP google single sign on signout will throw "Cannot read property 'getAuthInstance' of undefined" -


i have created google single sign on following steps mentioned in https://developers.google.com/identity/sign-in/web/sign-in

the sign in works charm when try integrate sign out per article in link

i following javascript error in console

uncaught typeerror: cannot read property 'getauthinstance' of undefined

and signout function looks like

<script>     function signout() {        var auth2 = gapi.auth2.getauthinstance();        auth2.signout().then(function () {           console.log('user signed out.');        });     } </script> 

and sign in looks

function onsignin(googleuser) {      var profile = googleuser.getbasicprofile();     console.log('id: ' + profile.getid());      console.log('name: ' + profile.getname());     console.log('image url: ' + profile.getimageurl());     console.log('email: ' + profile.getemail());  } 

are signin , signout used on same page? div g-signin2 loads , inits gapi.auth2 should work long on same page.

in case signout on separate page, should manually load , init gapi.auth2 library.

full example (you have replace your_client_id actual client_id):

<html> <head>    <meta name="google-signin-client_id" content="your_client_id"> </head> <body>   <script>     function signout() {       var auth2 = gapi.auth2.getauthinstance();       auth2.signout().then(function () {         console.log('user signed out.');       });     }      function onload() {       gapi.load('auth2', function() {         gapi.auth2.init();       });     }   </script>   <a href="#" onclick="signout();">sign out</a>    <script src="https://apis.google.com/js/platform.js?onload=onload" async defer></script> </body> </html> 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -