refs #6930 perf: refactor destroy method
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
0d3d002baf
commit
63d195cbbf
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue