#6930 - FIX bug logout #242

Merged
alexm merged 6 commits from 6930_fix_bug into dev 2024-03-18 12:35:02 +00:00
1 changed files with 43 additions and 26 deletions
Showing only changes of commit 445d95057a - Show all commits

View File

@ -2,9 +2,11 @@ import { useState } from './useState';
import { useRole } from './useRole';
import { useUserConfig } from './useUserConfig';
import axios from 'axios';
import useNotify from './useNotify';
export function useSession() {
const { notify } = useNotify();
function getToken() {
const localToken = localStorage.getItem('token');
const sessionToken = sessionStorage.getItem('token');
@ -29,37 +31,52 @@ export function useSession() {
}
async function destroy() {
if (localStorage.getItem('tokenMultimedia')){
await axios.post('VnUsers/logoutMultimedia', null, {
headers: {Authorization: localStorage.getItem('tokenMultimedia') }
});
localStorage.removeItem('tokenMultimedia')
if (localStorage.getItem('tokenMultimedia')) {
try {
await axios.post('Accounts/logout', null, {
headers: { Authorization: localStorage.getItem('tokenMultimedia') },
});
} catch (error) {
notify('errors.userConfig', 'negative');
} finally {
localStorage.removeItem('tokenMultimedia');
}
}
if (localStorage.getItem('token')){
await axios.post('VnUsers/logout', null, {
headers: {Authorization: localStorage.getItem('token') }
});
localStorage.removeItem('token')
if (localStorage.getItem('token')) {
try {
await axios.post('VnUsers/logout', null, {
headers: { Authorization: localStorage.getItem('token') },
});
} catch (error) {
notify('errors.userConfig', 'negative');
} finally {
localStorage.removeItem('token');
}
}
if (sessionStorage.getItem('tokenMultimedia')){
await axios.post('VnUsers/logoutMultimedia', null, {
headers: {Authorization: sessionStorage.getItem('tokenMultimedia') }
});
sessionStorage.removeItem('tokenMultimedia')
if (sessionStorage.getItem('tokenMultimedia')) {
try {
await axios.post('Accounts/logout', null, {
headers: { Authorization: sessionStorage.getItem('tokenMultimedia') },
});
} catch (error) {
notify('errors.userConfig', 'negative');
} finally {
sessionStorage.removeItem('tokenMultimedia');
}
}
if (sessionStorage.getItem('token')){
await axios.post('VnUsers/logout', null, {
headers: {Authorization: sessionStorage.getItem('token') }
});
sessionStorage.removeItem('token')
if (sessionStorage.getItem('token')) {
try {
await axios.post('VnUsers/logout', null, {
headers: { Authorization: sessionStorage.getItem('token') },
});
} catch (error) {
notify('errors.userConfig', 'negative');
} finally {
sessionStorage.removeItem('token');
}
}
const { setUser } = useState();
setUser({