refs #6930 feat: trycatchfinally logout
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2024-03-15 12:42:08 +01:00
parent 0fe0a6385b
commit 445d95057a
1 changed files with 43 additions and 26 deletions

View File

@ -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');
@ -30,35 +32,50 @@ export function useSession() {
async function destroy() {
if (localStorage.getItem('tokenMultimedia')) {
await axios.post('VnUsers/logoutMultimedia', null, {
headers: {Authorization: localStorage.getItem('tokenMultimedia') }
try {
await axios.post('Accounts/logout', null, {
headers: { Authorization: localStorage.getItem('tokenMultimedia') },
});
localStorage.removeItem('tokenMultimedia')
} catch (error) {
notify('errors.userConfig', 'negative');
} finally {
localStorage.removeItem('tokenMultimedia');
}
}
if (localStorage.getItem('token')) {
try {
await axios.post('VnUsers/logout', null, {
headers: {Authorization: localStorage.getItem('token') }
headers: { Authorization: localStorage.getItem('token') },
});
localStorage.removeItem('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') }
try {
await axios.post('Accounts/logout', null, {
headers: { Authorization: sessionStorage.getItem('tokenMultimedia') },
});
sessionStorage.removeItem('tokenMultimedia')
} catch (error) {
notify('errors.userConfig', 'negative');
} finally {
sessionStorage.removeItem('tokenMultimedia');
}
}
if (sessionStorage.getItem('token')) {
try {
await axios.post('VnUsers/logout', null, {
headers: {Authorization: sessionStorage.getItem('token') }
headers: { Authorization: sessionStorage.getItem('token') },
});
sessionStorage.removeItem('token')
} catch (error) {
notify('errors.userConfig', 'negative');
} finally {
sessionStorage.removeItem('token');
}
}
const { setUser } = useState();