From abd0733ad122a2c5f8774b0622a01926f514cfc7 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 26 Dec 2019 09:56:58 +0000 Subject: [PATCH] added logout service --- src/components/app/Popouts/Popouts/Settings.vue | 8 +++++--- src/services/AuthenticationService.js | 3 +++ src/store/modules/userModule.js | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/app/Popouts/Popouts/Settings.vue b/src/components/app/Popouts/Popouts/Settings.vue index abaae75..98852e3 100644 --- a/src/components/app/Popouts/Popouts/Settings.vue +++ b/src/components/app/Popouts/Popouts/Settings.vue @@ -99,9 +99,11 @@ export default { methods: { logout() { this.$store.dispatch("logout"); - isElectron - ? (window.location.href = "/login") - : (window.location.href = "/"); + setTimeout(() => { + isElectron + ? (window.location.href = "/login") + : (window.location.href = "/"); + }, 1000); }, close() { this.$store.dispatch("setPopoutVisibility", { diff --git a/src/services/AuthenticationService.js b/src/services/AuthenticationService.js index 274c32f..6fd204a 100644 --- a/src/services/AuthenticationService.js +++ b/src/services/AuthenticationService.js @@ -7,6 +7,9 @@ export default { login(credentials) { return wrapper(instance().post("user/login", credentials)); }, + logout() { + return wrapper(instance().delete("user/logout")); + }, user() { return wrapper(instance().get("user")); } diff --git a/src/store/modules/userModule.js b/src/store/modules/userModule.js index 7c7b131..6dc2422 100644 --- a/src/store/modules/userModule.js +++ b/src/store/modules/userModule.js @@ -1,6 +1,7 @@ import axios from "axios"; import Vue from "vue"; import NotificationSounds from "@/utils/notificationSound"; +import AuthenticationService from "@/services/AuthenticationService"; const state = { token: localStorage.getItem("hauthid") || null, @@ -27,8 +28,9 @@ const actions = { user(context, user) { context.commit("user", user); }, - logout(context) { + async logout(context) { axios.defaults.headers.common["authorization"] = ""; + await AuthenticationService.logout(); localStorage.clear(); context.commit("logout"); },