handle multiple logouts

This commit is contained in:
aj 2017-08-15 17:40:10 +00:00
parent 0c69462255
commit 1ccf0dd71c
2 changed files with 30 additions and 5 deletions

View File

@ -126,8 +126,14 @@ app.controller('loginCtrl', [
}; };
vm.signOut = function () { vm.signOut = function () {
Auth.signOut(); // TODO the sign-out url for each account should be fixed.
return Auth.signOut().then(function () {
if (!Auth.hasSession()) {
$location.path('/splash-page'); $location.path('/splash-page');
return;
}
window.alert("You are still logged in with other accounts.");
});
}; };
}]); }]);

View File

@ -30,7 +30,7 @@ app.factory('Auth', [
localStorage.setItem(dapName, JSON.stringify(session)); localStorage.setItem(dapName, JSON.stringify(session));
localStorage.setItem(dapSession, dapName); localStorage.setItem(dapSession, dapName);
obj[dapName] = true; obj[dapName] = Date.now();
localStorage.setItem(dapSessions, JSON.stringify(obj)); localStorage.setItem(dapSessions, JSON.stringify(obj));
} }
, restore: function () { , restore: function () {
@ -54,7 +54,26 @@ app.factory('Auth', [
return Auth.session; return Auth.session;
} }
, signOut: function () { , signOut: function () {
localStorage.clear(); var session = Auth.session;
var dapName = 'dap-' + session.subject + '|' + session.issuer;
// TODO logout url should be created upon login and remain fixed throughout the duration of the session (or on session restoration)
return Auth.oauth3.logout().then(function () {
var obj = JSON.parse(localStorage.getItem(dapSessions) || '{}');
delete obj[dapName];
var newDapName = Object.keys(obj).sort(function (a, b) { return obj[a] - obj[b]; })[0];
localStorage.setItem(dapSession, newDapName);
localStorage.setItem(dapSessions, JSON.stringify(obj));
localStorage.removeItem(dapName);
if (!newDapName) {
localStorage.removeItem(dapSession);
}
return Auth.restore();
});
// localStorage.clear();
} }
, sessions: [] , sessions: []
, session: null , session: null