Facebook Logout with Firebase & Ionic - Clear OAuth session so new user can login

How can you implement a Facebook logout that also log’s the person out of the OAuth provider?

I am currently using AngularFire’s $authWithOAuthPopup method.

The main functionality wanted is the ability for someone else to login to the app. I’m surprised there aren’t more questions around this on the web. What are possible work arounds, or methods?

Current behavior: Log user out > click login > uses previous FB session’s information to login.
Wanted behavior: Log user out > click login > asks for user’s FB credentials > login.

$scope.logout = function () {
  delete $localStorage.storageAuth;
  Auth.$unauth();
  $state.go('user.signin');
};

can we see the login/auth code… what are you doing with$localStorage.storageAuth you really shouldn’t need it for firebase since it will manage the the user’s login state for you… I believe…

but you can try and clear the cookies/session information

// _blank loads in background, might need clearsessioncache
var ref = window.open(url, '_blank', 'location=no,toolbar=no,clearcache=yes');

// attach a listener to the window which closes it when complete
ref.addEventListener('loadstop', function(event) { 
    ref.close();
});

See documentation https://github.com/apache/cordova-plugin-inappbrowser

1 Like

Aaron,

Thanks for the response and the solution.

You are correct about the $localStorage.storageAuth not being required. It was part of my login workflow and has been removed from my code.

The solution works… halfway… It prompts the same user to re-enter their password, BUT, does not allow for a new Facebook login user.

image

I’ve attached my login code for completeness:

Auth.$authWithOAuthPopup(‘facebook’, [{remember: “sessionOnly”}]).then(function (authData) {
//Save authData into $localStorage
})

Is there no way to ask for a new user, or send the user to an oAuth popup that asks for a new user?

So odd this isn’t officially implemented somehow. Thanks for your help Aaron.

Did you clear session or sessionCache?

Aaron,
It works! Thanks for the help.

I currently have the following options and it prompts for the username and password.

$scope.logout = function () {
var options = {
location: ‘yes’,
clearcache: ‘yes’,
toolbar: ‘no’,
hidden: ‘yes’
};
// _blank loads in background, might need clearsessioncache
$rootScope.$on(‘$cordovaInAppBrowser:loadstop’, function(e, event){
$cordovaInAppBrowser.close();
});
$cordovaInAppBrowser.open(‘http://www.google.com’, ‘_blank’, options);
}

Thanks again :slight_smile: I’ll upload the answer on SO as well on your behalf, or you can update too.