Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Sign Out Using When Using Google+ Sign-In

Google documents there gapi.auth.signOut() method here: https://developers.google.com/+/web/signin/#sign-out

The catch is that it says you can only call that method after the signinCallback has fired. So far as I can tell, the only way to fire the signinCallback is to put a sign-in button on the page.

This works great on my sign-in page itself, but as soon as I've authenticated a user, there's no need to put the G+ sign-in button on subsequent pages. I just want to have a small 'log out' link in the corner that the user can click to sign-out.

I tried having my log-out link call gapi.auth.signOut() but it does nothing unless I am also showing a useless log-in button. How do I get this to work?

like image 556
dave mankoff Avatar asked Oct 14 '13 03:10

dave mankoff


1 Answers

The button just has to be in the DOM, it doesn't have to be showing. What seems to work well is:

  1. Create a hidden element and attach the gapi handler with gapi.signin.render
  2. Wait for the immediate_failed error - display the button then
  3. Otherwise, accept the signed in callback, and display the logout button

Then you'll get a callback every time, but only show the button when signed out.

like image 65
Ian Barber Avatar answered Oct 21 '22 10:10

Ian Barber