From c4fae48b1d9f094fc4c4f75c702fd1e91c5ae4c4 Mon Sep 17 00:00:00 2001 From: ogerly Date: Wed, 8 Feb 2023 09:44:21 +0100 Subject: [PATCH] toast by automatically logged out --- frontend/src/components/SessionLogoutTimeout.vue | 2 ++ frontend/src/mixins/toaster.js | 11 ++++++++++- frontend/src/pages/Login.vue | 6 ++++++ frontend/src/store/store.js | 5 +++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/SessionLogoutTimeout.vue b/frontend/src/components/SessionLogoutTimeout.vue index 1ebff752a..7a7cdfc5e 100644 --- a/frontend/src/components/SessionLogoutTimeout.vue +++ b/frontend/src/components/SessionLogoutTimeout.vue @@ -67,6 +67,7 @@ export default { } if (this.tokenExpiresInSeconds === 0) { this.$timer.stop('tokenExpires') + this.$store.commit('automaticallyLoggedOut', true) this.$emit('logout') } }, @@ -84,6 +85,7 @@ export default { }) .catch(() => { this.$timer.stop('tokenExpires') + this.$store.commit('automaticallyLoggedOut', true) this.$emit('logout') }) }, diff --git a/frontend/src/mixins/toaster.js b/frontend/src/mixins/toaster.js index 175ffeec0..109bf0d9a 100644 --- a/frontend/src/mixins/toaster.js +++ b/frontend/src/mixins/toaster.js @@ -4,24 +4,33 @@ export const toasters = { this.toast(message, { title: this.$t('success'), variant: 'success', + autoHideDelay: 5000, }) }, toastError(message) { this.toast(message, { title: this.$t('error.error'), variant: 'danger', + autoHideDelay: 5000, }) }, toastInfo(message) { this.toast(message, { title: this.$t('navigation.info'), variant: 'warning', + autoHideDelay: 5000, + }) + }, + toastInfoNoHide(message) { + this.toast(message, { + title: this.$t('navigation.info'), + variant: 'warning', + noAutoHide: true, }) }, toast(message, options) { if (message.replace) message = message.replace(/^GraphQL error: /, '') this.$root.$bvToast.toast(message, { - autoHideDelay: 5000, appendToast: true, solid: true, toaster: 'b-toaster-top-right', diff --git a/frontend/src/pages/Login.vue b/frontend/src/pages/Login.vue index bd07af3ef..5e2597c45 100755 --- a/frontend/src/pages/Login.vue +++ b/frontend/src/pages/Login.vue @@ -123,5 +123,11 @@ export default { return !this.showPageMessage }, }, + mounted() { + if (this.$store.state.automaticallyLoggedOut) { + this.toastInfoNoHide('Du wurdest automatisch abgemeldet') + this.$store.commit('automaticallyLoggedOut', false) + } + }, } diff --git a/frontend/src/store/store.js b/frontend/src/store/store.js index 1cd874c06..8f87cf468 100644 --- a/frontend/src/store/store.js +++ b/frontend/src/store/store.js @@ -53,6 +53,9 @@ export const mutations = { hideAmountGDT: (state, hideAmountGDT) => { state.hideAmountGDT = !!hideAmountGDT }, + automaticallyLoggedOut: (state, automaticallyLoggedOut) => { + state.automaticallyLoggedOut = !!automaticallyLoggedOut + }, } export const actions = { @@ -68,6 +71,7 @@ export const actions = { commit('isAdmin', data.isAdmin) commit('hideAmountGDD', data.hideAmountGDD) commit('hideAmountGDT', data.hideAmountGDT) + commit('automaticallyLoggedOut', false) }, logout: ({ commit, state }) => { commit('token', null) @@ -108,6 +112,7 @@ try { publisherId: null, hideAmountGDD: null, hideAmountGDT: null, + automaticallyLoggedOut: false, }, getters: {}, // Syncronous mutation of the state