Clientside-only user logout (currently only useful for after deletion; we generally want to invalidate the session as well)

This commit is contained in:
Dannon Baker
2020-09-30 23:27:37 -04:00
parent 9d2cc0da69
commit 399939fdf8
2 changed files with 24 additions and 7 deletions
@@ -88,7 +88,7 @@ import _l from "utils/localization";
import axios from "axios";
import QueryStringParsing from "utils/query-string-parsing";
import { getUserPreferencesModel } from "components/User/UserPreferencesModel";
import { userLogoutAll } from "layout/menu";
import { userLogoutAll, userLogoutClient } from "layout/menu";
import "@fortawesome/fontawesome-svg-core";
Vue.use(BootstrapVue);
@@ -254,7 +254,7 @@ export default {
return false;
}
}
userLogoutAll();
userLogoutClient();
} else {
this.nameState = false;
return false;
+22 -5
View File
@@ -3,10 +3,12 @@ import { getGalaxyInstance } from "app";
import _l from "utils/localization";
import { CommunicationServerView } from "layout/communication-server-view";
export function userLogoutAll() {
return userLogout(true);
}
const POST_LOGOUT_URL = "root/login?is_logout_redirect=true";
/**
* Handles user logout. Invalidates the current session, checks to see if we
* need to log out of OIDC too, and goes to our POST_LOGOUT_URL (or some other
* configured redirect). */
export function userLogout(logoutAll = false) {
const galaxy = getGalaxyInstance();
const session_csrf_token = galaxy.session_csrf_token;
@@ -25,14 +27,29 @@ export function userLogout(logoutAll = false) {
}
})
.then((response) => {
if (response.data && response.data.redirect_uri) {
if (response.data?.redirect_uri) {
window.top.location.href = response.data.redirect_uri;
} else {
window.top.location.href = `${galaxy.root}root/login?is_logout_redirect=true`;
window.top.location.href = `${galaxy.root}${POST_LOGOUT_URL}`;
}
});
}
/** User logout with 'log out all sessions' flag set. This will invalidate all
* active sessions a user might have. */
export function userLogoutAll() {
return userLogout(true);
}
/** Purely clientside logout, dumps session and redirects without invalidating
* serverside. Currently only used when marking an account deleted -- any
* subsequent navigation after the deletion API request would fail otherwise */
export function userLogoutClient() {
const galaxy = getGalaxyInstance();
galaxy.user?.clearSessionStorage();
window.top.location.href = `${galaxy.root}${POST_LOGOUT_URL}`;
}
export function fetchMenu(options = {}) {
const Galaxy = getGalaxyInstance();
const menu = [];