refs #6930 feat: trycatchfinally logout
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
0fe0a6385b
commit
445d95057a
|
@ -2,9 +2,11 @@ import { useState } from './useState';
|
||||||
import { useRole } from './useRole';
|
import { useRole } from './useRole';
|
||||||
import { useUserConfig } from './useUserConfig';
|
import { useUserConfig } from './useUserConfig';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
import useNotify from './useNotify';
|
||||||
|
|
||||||
export function useSession() {
|
export function useSession() {
|
||||||
|
const { notify } = useNotify();
|
||||||
|
|
||||||
function getToken() {
|
function getToken() {
|
||||||
const localToken = localStorage.getItem('token');
|
const localToken = localStorage.getItem('token');
|
||||||
const sessionToken = sessionStorage.getItem('token');
|
const sessionToken = sessionStorage.getItem('token');
|
||||||
|
@ -29,37 +31,52 @@ export function useSession() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function destroy() {
|
async function destroy() {
|
||||||
if (localStorage.getItem('tokenMultimedia')){
|
if (localStorage.getItem('tokenMultimedia')) {
|
||||||
await axios.post('VnUsers/logoutMultimedia', null, {
|
try {
|
||||||
headers: {Authorization: localStorage.getItem('tokenMultimedia') }
|
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')){
|
if (localStorage.getItem('token')) {
|
||||||
await axios.post('VnUsers/logout', null, {
|
try {
|
||||||
headers: {Authorization: localStorage.getItem('token') }
|
await axios.post('VnUsers/logout', null, {
|
||||||
});
|
headers: { Authorization: localStorage.getItem('token') },
|
||||||
localStorage.removeItem('token')
|
});
|
||||||
|
} catch (error) {
|
||||||
|
notify('errors.userConfig', 'negative');
|
||||||
|
} finally {
|
||||||
|
localStorage.removeItem('token');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sessionStorage.getItem('tokenMultimedia')) {
|
||||||
if (sessionStorage.getItem('tokenMultimedia')){
|
try {
|
||||||
await axios.post('VnUsers/logoutMultimedia', null, {
|
await axios.post('Accounts/logout', null, {
|
||||||
headers: {Authorization: sessionStorage.getItem('tokenMultimedia') }
|
headers: { Authorization: sessionStorage.getItem('tokenMultimedia') },
|
||||||
});
|
});
|
||||||
sessionStorage.removeItem('tokenMultimedia')
|
} catch (error) {
|
||||||
|
notify('errors.userConfig', 'negative');
|
||||||
|
} finally {
|
||||||
|
sessionStorage.removeItem('tokenMultimedia');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (sessionStorage.getItem('token')){
|
if (sessionStorage.getItem('token')) {
|
||||||
await axios.post('VnUsers/logout', null, {
|
try {
|
||||||
headers: {Authorization: sessionStorage.getItem('token') }
|
await axios.post('VnUsers/logout', null, {
|
||||||
});
|
headers: { Authorization: sessionStorage.getItem('token') },
|
||||||
sessionStorage.removeItem('token')
|
});
|
||||||
|
} catch (error) {
|
||||||
|
notify('errors.userConfig', 'negative');
|
||||||
|
} finally {
|
||||||
|
sessionStorage.removeItem('token');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const { setUser } = useState();
|
const { setUser } = useState();
|
||||||
|
|
||||||
setUser({
|
setUser({
|
||||||
|
|
Loading…
Reference in New Issue