diff --git a/src/composables/useSession.js b/src/composables/useSession.js index d397d7ed9..c7f7db24e 100644 --- a/src/composables/useSession.js +++ b/src/composables/useSession.js @@ -3,31 +3,29 @@ import { useRole } from './useRole'; import { useUserConfig } from './useUserConfig'; import axios from 'axios'; import useNotify from './useNotify'; +const TOKEN_MULTIMEDIA = 'tokenMultimedia'; +const TOKEN = 'token'; export function useSession() { const { notify } = useNotify(); function getToken() { - const localToken = localStorage.getItem('token'); - const sessionToken = sessionStorage.getItem('token'); + const localToken = localStorage.getItem(TOKEN); + const sessionToken = sessionStorage.getItem(TOKEN); return localToken || sessionToken || ''; } function getTokenMultimedia() { - const localTokenMultimedia = localStorage.getItem('token'); // Temporal - const sessionTokenMultimedia = sessionStorage.getItem('token'); // Temporal + const localTokenMultimedia = localStorage.getItem(); + const sessionTokenMultimedia = sessionStorage.getItem(TOKEN_MULTIMEDIA); return localTokenMultimedia || sessionTokenMultimedia || ''; } function setToken(data) { - if (data.keepLogin) { - localStorage.setItem('token', data.token); - localStorage.setItem('tokenMultimedia', data.tokenMultimedia); - } else { - sessionStorage.setItem('token', data.token); - sessionStorage.setItem('tokenMultimedia', data.tokenMultimedia); - } + const storage = data.keepLogin ? localStorage : sessionStorage; + storage.setItem(TOKEN, data.token); + storage.setItem(TOKEN_MULTIMEDIA, data.tokenMultimedia); } async function destroyToken(url, storage, key) { if (storage.getItem(key)) { @@ -71,8 +69,8 @@ export function useSession() { } function isLoggedIn() { - const localToken = localStorage.getItem('token'); - const sessionToken = sessionStorage.getItem('token'); + const localToken = localStorage.getItem(TOKEN); + const sessionToken = sessionStorage.getItem(TOKEN); return !!(localToken || sessionToken); }