FirebaseExtended / angularfire

AngularJS bindings for Firebase
MIT License
2.73k stars 631 forks source link

When used firebase.auth().signOut() with a promise leaves the "firebase:host:project-xxxxxxxxxxxxxx.firebaseio.com" key undeleted in localstorage #903

Closed ghost closed 7 years ago

ghost commented 7 years ago

Version info

Angular: 1.5.3 Firebase: v3.6.4 AngularFire: 2.2.0 Other (e.g. Node, browser, operating system) (if applicable): Ionic Framework 1.3.2

Test case

I had to explicitly delete the "firebase:host:project-xxxxxxxxxxxxxx.firebaseio.com" key from localstorage like below:

firebase.auth().signOut().then(function() {
            // Sign-out successful.

            localStorage.removeItem("firebase:host:project-xxxxxxxxxxx.firebaseio.com");

            $state.go("login");

          }, function(error) {
            // An error happened.
            console.log(error);

          });

Steps to reproduce

When used firebase.auth().signOut() with a promise like above, still leaves the

"firebase:host:project-xxxxxxxxxxxxxx.firebaseio.com" key undeleted in localstorage.

Expected behavior

How to achieve a clean logout?

Actual behavior

"firebase:host:project-xxxxxxxxxxxxxx.firebaseio.com" key undeleted in localstorage and automatically reinitialise

katowulf commented 7 years ago

This isn't a test case. You haven't included sufficient code to recreate the conditions you've described here. Your code should be runnable, should recreate the error conditions, and describe how you verified that the signOut() method is called, and how you verified that the .then() method was not invoked.

katowulf commented 7 years ago

In case that's unclear, I'm not looking for a GitHub repro, but just some peripherals and some evidence that you've verified a) that signOut() is actually called here, that localStorage.removeItem() isn't just failing, and that the .then() method isn't invoked at all.

Note also that you should be using .catch() here, instead of logging errrs in the second method to .then() (which only catches errors thrown by signOut()), as any error thrown inside the .then() method would not be caught and could be swallowed.

If you can provide this, happy to investigate. ☃

bojeil-google commented 7 years ago

Hey @appplumbr, I'd love to help resolve this issue. It will help a lot if you can provided a link or code to reproduce.

I have a couple of questions:

  1. How are you initializing your firebase app?
  2. Are you running this from a browser? if so, which browser.
  3. Do you happen to use the Google sign in web library with this?
  4. Are you getting any errors or warnings in the console when signing out?
ghost commented 7 years ago

@bojeil-google - the project is confidential cannot share the code, still answer to above questions:

1) .constant("CONFIG", { "FIREBASE_API": 'xxxxxxxxxx', "FIREBASE_AUTH_DOMAIN": 'project-xxxxxxxxxx.firebaseapp.com', "FIREBASE_DB_URL": 'https://project-xxxxxxxxxx.firebaseio.com', "FIREBASE_STORAGE": 'project-xxxxxxxxxx.appspot.com', "MESSAGE_SENDER_ID": 'xxxxxxxxxx' });

2) ionic serve --lab command inside Ionic CLI (MAC OS) in chrome Version 55.0.2883.95 (64-bit)

3) No, I am using firebase.auth().signInWithEmailAndPassword() firebase custom login no social login as this point.

  1. After sign-out it goes inside .then(success) and leaves the localstorage undeleted.

One more observation, if I happen to login and force close/ kill the app without logout I see multiple connections ref in local storage like this below:

  1. firebase:authUser:XXXXXXXXXxxxxxxxxxxx:[DEFAULT]
  2. key > firebase:host:project-XXXXXXXXXxxxxxxxxxxx.firebaseio.com / value > "s-uscxc-nss-xxx.firebaseio.com"
  3. firebase:host:xxxxxxxxxxx.firebaseio.com

1, 2 and 3 are my different firebase projects that I logged in but did not signed out and just closed the browser / force close/ kill the firebase apps on device.

Ideally on Signout, all my local storage references related to my firebase project should be deleted.

Please note: on mobile devices and tablets its same localstorage undeleted, try a sample app using firebase.auth().signInWithEmailAndPassword() and use

$scope.doLogout = function(){

        firebase.auth().signOut().then(function() {
            // Sign-out successful.
            console.log("Logout successful");

            //localStorage.clear(); This works but not recommended 
            //localStorage.removeItem("firebase:host:project-xxxxxxxxxx.firebaseio.com"); This is currently am doing in my project

            $state.go("login");

          }, function(error) {
            // An error happened.
            console.log(error);

          });
   }

post signout see your localstorage, connect your device via device debugging of chrome browser: chrome://inspect > go to application tab > localstorage.

katowulf commented 7 years ago

@appplumbr a minimal repro does not need to involve your proprietary code, in fact, it should not. You do need to provide enough code for us to understand the problem and reproduce it. You do this by starting a test app and adding sufficient code until you can recreate the same conditions, and sharing that. It doesn't need to be runnable by us in every case, but this certainly doesn't hurt.

Additionally, and most importantly, you need to complete your due diligence here and show that you've verified:

bojeil-google commented 7 years ago

Ok, the auth library stores the auth state in the following key: firebase:authUser:API_KEY:APP_NAME So on sign out, this is the only data that is removed. So from Auth perspective, this works as intended. I am not sure which other service stores data in the key that is not being cleared in your situation: firebase:host:project-xxxxxxxxxx.firebaseio.com I checked. This is database related. Will reassign for explanation.

jwngr commented 7 years ago

This seems to be working as intended. The use of local storage by the Firebase SDK is an implementation detail and you should not need to be concerned about what we store in there. It looks like the $signOut() method is properly removing the auth key from local storage. The database key should stay in local storage since the Firebase SDK can still be used while a user is not signed in.

mikelehen commented 7 years ago

As a bit of additional color, the database key caches the hostname of the server currently serving your Database instance and so it improves future connection times by saving a round-trip. You could delete it if it's bothering you, but it may hurt future page load times.

ghost commented 7 years ago

Thank you! all for your help and quick insight

dimitri320 commented 6 years ago

I'm experiencing this same exact problem. Here is my code for logout. Basically firebase.auth().signOut() doesn't do anything. Upon logining in (I'm using Facebook), it dosn't even check that Facebook is logged out itself, and continues to re-load the old credentials.

And I've check Facebook logout status, all fine, so it's not a problem on the side of Facebook.

I'm running iOS with ionic.

  logoutUser(): Promise<any> {
    return new Promise((resolve, reject) => {
      return this.fb.logout().then((logoutPromise) => {
        return this.fb.getLoginStatus().then((status) => {
          this.firebase.auth().signOut().then((firebaseSignOutResult) => {
            return resolve();
          })
        });
      });
    });
  }
NDMCreative commented 5 years ago

dimitri320

I'm experiencing this same exact problem. Here is my code for logout. Basically firebase.auth().signOut() doesn't do anything. Upon logining in (I'm using Facebook), it dosn't even check that Facebook is logged out itself, and continues to re-load the old credentials.

And I've check Facebook logout status, all fine, so it's not a problem on the side of Facebook.

I'm running iOS with ionic.

  logoutUser(): Promise<any> {
    return new Promise((resolve, reject) => {
      return this.fb.logout().then((logoutPromise) => {
        return this.fb.getLoginStatus().then((status) => {
          this.firebase.auth().signOut().then((firebaseSignOutResult) => {
            return resolve();
          })
        });
      });
    });
  }
this works, for ionic use angular AngularFireAuth

import { AngularFireAuth } from '@angular/fire/auth';
 constructor(
    public _afAuth: AngularFireAuth
){

public async logoutUser(): Promise<any> {

    try {

      return await this._afAuth.auth.signOut();
    } catch (e) {
      console.error("big hu?", e);
    }

  }
Kalp1498 commented 4 years ago

Version info

Angular: 1.5.3 Firebase: v3.6.4 AngularFire: 2.2.0 Other (e.g. Node, browser, operating system) (if applicable): Ionic Framework 1.3.2

Test case

I had to explicitly delete the "firebase:host:project-xxxxxxxxxxxxxx.firebaseio.com" key from localstorage like below:

firebase.auth().signOut().then(function() {
            // Sign-out successful.

            localStorage.removeItem("firebase:host:project-xxxxxxxxxxx.firebaseio.com");

            $state.go("login");

          }, function(error) {
            // An error happened.
            console.log(error);

          });

Steps to reproduce

When used firebase.auth().signOut() with a promise like above, still leaves the

"firebase:host:project-xxxxxxxxxxxxxx.firebaseio.com" key undeleted in localstorage.

Expected behavior

How to achieve a clean logout?

  • When pressing back button post logout() this key should not be automatically initiated

Actual behavior

"firebase:host:project-xxxxxxxxxxxxxx.firebaseio.com" key undeleted in localstorage and automatically reinitialise

Though you have your own problem but i found mine solution under your problem Thanks bud..