From b95d44c05d765a12cdb5f0fd6502b310a33716fc Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 17 Apr 2024 10:07:44 +0200 Subject: [PATCH 1/2] feat(lilium): refs #6930 Undo rollback lilium --- src/composables/useSession.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/composables/useSession.js b/src/composables/useSession.js index d397d7ed9..bfe46e50d 100644 --- a/src/composables/useSession.js +++ b/src/composables/useSession.js @@ -3,30 +3,32 @@ 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); + localStorage.setItem(TOKEN, data.token); + localStorage.setItem(TOKEN_MULTIMEDIA, data.tokenMultimedia); } else { - sessionStorage.setItem('token', data.token); - sessionStorage.setItem('tokenMultimedia', data.tokenMultimedia); + sessionStorage.setItem(TOKEN, data.token); + sessionStorage.setItem(TOKEN_MULTIMEDIA, data.tokenMultimedia); } } async function destroyToken(url, storage, key) { @@ -71,8 +73,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); } -- 2.40.1 From 37ad84f239b229ff269e09d1533908b5827c2a9e Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 17 Apr 2024 10:09:44 +0200 Subject: [PATCH 2/2] perf(lilium): refs #6930 Improve setToken fn --- src/composables/useSession.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/composables/useSession.js b/src/composables/useSession.js index bfe46e50d..c7f7db24e 100644 --- a/src/composables/useSession.js +++ b/src/composables/useSession.js @@ -23,13 +23,9 @@ export function useSession() { } function setToken(data) { - if (data.keepLogin) { - localStorage.setItem(TOKEN, data.token); - localStorage.setItem(TOKEN_MULTIMEDIA, data.tokenMultimedia); - } else { - sessionStorage.setItem(TOKEN, data.token); - sessionStorage.setItem(TOKEN_MULTIMEDIA, 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)) { -- 2.40.1