#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 20 additions and 45 deletions
Showing only changes of commit 63d195cbbf - Show all commits

View File

@ -29,52 +29,27 @@ export function useSession() {
sessionStorage.setItem('tokenMultimedia', data.tokenMultimedia);
}
}
async function destroyToken(url, storage, key) {
if (storage.getItem(key)) {
try {
await axios.post(url, null, {
headers: { Authorization: storage.getItem(key) },
});
} catch (error) {
notify('errors.statusUnauthorized', 'negative');
} finally {
storage.removeItem(key);
}
}
}
async function destroy() {
if (localStorage.getItem('tokenMultimedia')) {
try {
await axios.post('Accounts/logout', null, {
headers: { Authorization: localStorage.getItem('tokenMultimedia') },
});
} catch (error) {
notify('errors.statusUnauthorized', 'negative');
} finally {
localStorage.removeItem('tokenMultimedia');
}
}
if (localStorage.getItem('token')) {
try {
await axios.post('VnUsers/logout', null, {
headers: { Authorization: localStorage.getItem('token') },
});
} catch (error) {
notify('errors.statusUnauthorized', 'negative');
} finally {
localStorage.removeItem('token');
}
}
if (sessionStorage.getItem('tokenMultimedia')) {
try {
await axios.post('Accounts/logout', null, {
headers: { Authorization: sessionStorage.getItem('tokenMultimedia') },
});
} catch (error) {
notify('errors.statusUnauthorized', 'negative');
} finally {
sessionStorage.removeItem('tokenMultimedia');
}
}
if (sessionStorage.getItem('token')) {
try {
await axios.post('VnUsers/logout', null, {
headers: { Authorization: sessionStorage.getItem('token') },
});
} catch (error) {
notify('errors.statusUnauthorized', 'negative');
} finally {
sessionStorage.removeItem('token');
}
const tokens = {
tokenMultimedia: 'Accounts/logout',
token: 'VnUsers/logout',
};
for (const [key, url] of Object.entries(tokens)) {
await destroyToken(url, localStorage, key);
await destroyToken(url, sessionStorage, key);
}
const { setUser } = useState();