2

Using the very clear simple examples provided by Google (Firebase Google Auth)I have been unable to log out from google.

Everytime sign I call this method using a button, it allows me to log in and navigates me to the local host.

function logGoogle() {

firebase.auth().signInWithPopup(provider).then(function(result) {
  // This gives you a Google Access Token. You can use it to access the Google API.
  var token = result.credential.accessToken;
  // The signed-in user info.
  var user = result.user;
  location.href = 'http://localhost:8080';
  // ...
}).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // The email of the user's account used.
  var email = error.email;
  // The firebase.auth.AuthCredential type that was used.
  var credential = error.credential;
  // ...

  console.log(errorCode);
  console.log(errorMessage);
  console.log(email);
  console.log(credential);
});

}

however when i go back to the main menu which consists a log out button. It logs the session out, doesn't delete the session. When i log back in, i do not need to enter google creds. Bear in mind i am logged in to google chrome using an gmail account.

function logOutGoogle() {
  firebase.auth().signOut().then(function () {
    console.log("you logged off");

   
 location.href = 'http://localhost/GoogleVue3/';
  }).catch(function (error) {
    alert(error);
  });
}

I tried in incognito mode. entered google creds, went to the app, and decided to log out. Click on to sign in google, it automatically takes me to the app.

any advices?

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
xD-saleem
  • 97
  • 2
  • 8

2 Answers2

1

basically, firebase logout function logouts the application itself, but does not log out google on the browser.

To log out completely, you need the first sign out of the application then if successful, sign out of Google in the browser. This then allows users not to log again when they've logged out.

function signoff() {

  firebase.auth().signOut().then(function () {
    window.alert("you have signed off successfully")
    window.location = "https://mail.google.com/mail/u/0/?logout&hl=en";


    // document.location.href = "https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=http://localhost/GoogleVue4";


  }).catch(function (error) {
    console.log(error);

  })

}
xD-saleem
  • 97
  • 2
  • 8
1

You may not really want to sign out of Google in your browser (as it'll log you out of Gmail, and any other tabs/windows you're using Google apps). When you hit Firebase auth again, it jumps straight into the app (bypassing Google login because it was never really logged out of Google). Instead of logging in immediately, perhaps you want to see the Google account-picker. If so, here's the answer I gave to a related SO question.

Note that the issue you describe will only happen if you've only logged into a single Google/Gmail account, i.e., like you would in incog mode. If you've logged into >1, you'll always get the account-picker so Firebase can tell your app which user you've selected.

wescpy
  • 10,689
  • 3
  • 54
  • 53