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);
|
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();
|
||||||
|
|
Loading…
Reference in New Issue