refs #6930 perf: refactor destroy method
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2024-03-15 13:21:26 +01:00
parent 0d3d002baf
commit 63d195cbbf
1 changed files with 20 additions and 45 deletions

View File

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