diff --git a/src/boot/axios.js b/src/boot/axios.js index c58cc2d08..e3e7289af 100644 --- a/src/boot/axios.js +++ b/src/boot/axios.js @@ -11,7 +11,7 @@ axios.defaults.baseURL = '/api/'; const onRequest = (config) => { const token = session.getToken(); - if (token.length && config.headers) { + if (token.length && !config.headers.Authorization) { config.headers.Authorization = token; } diff --git a/src/composables/useSession.js b/src/composables/useSession.js index 4d182a934..580efbdf8 100644 --- a/src/composables/useSession.js +++ b/src/composables/useSession.js @@ -1,6 +1,7 @@ import { useState } from './useState'; import { useRole } from './useRole'; import { useUserConfig } from './useUserConfig'; +import axios from 'axios'; export function useSession() { @@ -27,15 +28,37 @@ export function useSession() { } } - function destroy() { - if (localStorage.getItem('token')) - localStorage.removeItem('token') - - if (localStorage.getItem('tokenMultimedia')) + async function destroy() { + if (localStorage.getItem('tokenMultimedia')){ + await axios.post('VnUsers/logoutMultimedia', null, { + headers: {Authorization: localStorage.getItem('tokenMultimedia') } + }); localStorage.removeItem('tokenMultimedia') - if (sessionStorage.getItem('token')) - sessionStorage.removeItem('token'); + } + if (localStorage.getItem('token')){ + await axios.post('VnUsers/logout', null, { + headers: {Authorization: localStorage.getItem('token') } + }); + localStorage.removeItem('token') + } + + + if (sessionStorage.getItem('tokenMultimedia')){ + await axios.post('VnUsers/logoutMultimedia', null, { + headers: {Authorization: sessionStorage.getItem('tokenMultimedia') } + }); + sessionStorage.removeItem('tokenMultimedia') + + } + if (sessionStorage.getItem('token')){ + await axios.post('VnUsers/logout', null, { + headers: {Authorization: sessionStorage.getItem('token') } + }); + sessionStorage.removeItem('token') + } + + const { setUser } = useState();