Mercurial > gemma
changeset 1701:f4bd67daaaff
feat: force login on invalid session
Redirect user to login when session becomes invalid.
Prototypical implementation for importqueue.
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Mon, 07 Jan 2019 12:13:52 +0100 |
parents | 0c0e658fcfc8 |
children | 49b89575ab31 |
files | client/src/components/Sidebar.vue client/src/components/importqueue/Importqueue.vue client/src/lib/session.js |
diffstat | 3 files changed, 17 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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 <markus.kottlaender@intevation.de> */ 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("/");
--- 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}`
--- 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 <thomas.junk@intevation.de> */ +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 };