#6930 - FIX bug logout #242
|
@ -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({
|
||||
|
|
Loading…
Reference in New Issue