# HG changeset patch # User Thomas Junk # Date 1546859632 -3600 # Node ID f4bd67daaaffd18004be2bb849cf516a9f008f50 # Parent 0c0e658fcfc8e0d2c9de566098cdd3ac4c7b7acc feat: force login on invalid session Redirect user to login when session becomes invalid. Prototypical implementation for importqueue. diff -r 0c0e658fcfc8 -r f4bd67daaaff client/src/components/Sidebar.vue --- a/client/src/components/Sidebar.vue Mon Jan 07 11:35:35 2019 +0100 +++ b/client/src/components/Sidebar.vue Mon Jan 07 12:13:52 2019 +0100 @@ -136,7 +136,7 @@ * Markus Kottländer */ import { mapGetters, mapState } from "vuex"; -import app from "@/main"; +import { logOff } from "@/lib/session.js"; export default { name: "sidebar", @@ -175,10 +175,7 @@ IMPORTSTRETCHES: process.env.VUE_APP_FEATURE_IMPORTSTRETCHES, methods: { logoff() { - app.$snotify.clear(); - this.$store.commit("reset"); - this.$store.commit("user/clearAuth"); - this.$router.push("/login"); + logOff(); }, toggleContextBox(context) { if (this.$route.path !== "/") this.$router.push("/"); diff -r 0c0e658fcfc8 -r f4bd67daaaff client/src/components/importqueue/Importqueue.vue --- a/client/src/components/importqueue/Importqueue.vue Mon Jan 07 11:35:35 2019 +0100 +++ b/client/src/components/importqueue/Importqueue.vue Mon Jan 07 12:13:52 2019 +0100 @@ -109,6 +109,7 @@ import { displayError } from "@/lib/errors.js"; import { mapState } from "vuex"; import { HTTP } from "@/lib/http.js"; +import { logOff } from "@/lib/session.js"; export default { name: "importqueue", @@ -156,6 +157,10 @@ }) .catch(error => { const { status, data } = error.response; + if (status === 401) { + logOff(); + return; + } displayError({ title: this.$gettext("Backend Error"), message: `${status}: ${data.message || data}` diff -r 0c0e658fcfc8 -r f4bd67daaaff client/src/lib/session.js --- a/client/src/lib/session.js Mon Jan 07 11:35:35 2019 +0100 +++ b/client/src/lib/session.js Mon Jan 07 12:13:52 2019 +0100 @@ -12,6 +12,15 @@ * Thomas Junk */ +import app from "@/main"; + +const logOff = () => { + app.$snotify.clear(); + app.$store.commit("reset"); + app.$store.commit("user/clearAuth"); + app.$router.push("/login"); +}; + /** * Compares whether session is current * based on the expiry information and the @@ -34,4 +43,4 @@ return timestring * 1000; } -export { sessionStillActive, toMillisFromString }; +export { logOff, sessionStillActive, toMillisFromString };