From 7fcd57f72ad76ad8265a2d9d99ffe628482cd85d Mon Sep 17 00:00:00 2001 From: Jorge Miguel Lobo Escalona Date: Fri, 1 Apr 2022 11:57:08 +0200 Subject: [PATCH] F #5786: fireedge only use localStorage (#1898) --- src/fireedge/etc/fireedge-server.conf | 5 +++-- .../src/client/features/AuthApi/index.js | 4 ++-- .../src/client/features/General/slice.js | 1 - src/fireedge/src/client/utils/storage.js | 21 +++++-------------- .../src/server/routes/api/auth/utils.js | 2 +- .../src/server/routes/entrypoints/App.js | 6 ++++-- 6 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/fireedge/etc/fireedge-server.conf b/src/fireedge/etc/fireedge-server.conf index 7809c0f2c19..93e6f7dfaaf 100644 --- a/src/fireedge/etc/fireedge-server.conf +++ b/src/fireedge/etc/fireedge-server.conf @@ -20,11 +20,12 @@ one_xmlrpc: 'http://localhost:2633/RPC2' # Flow Server: use it if you have flow-server and fireedge on different servers oneflow_server: 'http://localhost:2474' - - # life expiration time (minutes) session_expiration: 180 +# life expiration time when use the check remember into login (minutes) +session_remember_expiration: 3600 + # minimum life expiration time (minutes) minimun_opennebula_expiration: 30 diff --git a/src/fireedge/src/client/features/AuthApi/index.js b/src/fireedge/src/client/features/AuthApi/index.js index f8482065cb4..ed0a7fdf641 100644 --- a/src/fireedge/src/client/features/AuthApi/index.js +++ b/src/fireedge/src/client/features/AuthApi/index.js @@ -88,12 +88,12 @@ const authApi = createApi({ isLoginInProgress: withGroupSwitcher && !!token && !isOneAdmin, } }, - async onQueryStarted({ remember }, { queryFulfilled, dispatch }) { + async onQueryStarted(_, { queryFulfilled, dispatch }) { try { const { data: queryData } = await queryFulfilled if (queryData?.jwt) { - storage(JWT_NAME, queryData?.jwt, remember) + storage(JWT_NAME, queryData?.jwt) dispatch(dismissSnackbar({ dismissAll: true })) } diff --git a/src/fireedge/src/client/features/General/slice.js b/src/fireedge/src/client/features/General/slice.js index 6135362b94d..e0053937da0 100644 --- a/src/fireedge/src/client/features/General/slice.js +++ b/src/fireedge/src/client/features/General/slice.js @@ -28,7 +28,6 @@ const initial = { withGroupSwitcher: false, isLoading: false, isFixMenu: false, - notifications: [], } diff --git a/src/fireedge/src/client/utils/storage.js b/src/fireedge/src/client/utils/storage.js index d45ac87a1df..6c414779d4c 100644 --- a/src/fireedge/src/client/utils/storage.js +++ b/src/fireedge/src/client/utils/storage.js @@ -18,19 +18,11 @@ import root from 'window-or-global' /** * Save an item in the browser storage. * - * @param {string} name - * - Name of item in the storage - * @param {string} data - * - Data will be saved into storage - * @param {boolean} keepData - * - If `true`, save the data in local storage, instead of session storage + * @param {string} name - Name of item in the storage + * @param {string} data - The data will be saved into local storage */ -export const storage = (name = '', data = '', keepData = false) => { - if (name && data) { - keepData - ? root?.localStorage?.setItem(name, data) - : root?.sessionStorage?.setItem(name, data) - } +export const storage = (name = '', data = '') => { + name && data && root?.localStorage?.setItem(name, data) } /** @@ -43,7 +35,6 @@ export const removeStoreData = (items = []) => { itemsToRemove.forEach((item) => { root?.localStorage?.removeItem(item) - root?.sessionStorage?.removeItem(item) }) } @@ -51,13 +42,11 @@ export const removeStoreData = (items = []) => { * Looking for an item in the browser storage. * * @param {string} name - Name of item - * @returns {object|string} Returns the item if found it + * @returns {false|string} Returns the item if found it */ export const findStorageData = (name = '') => { if (name && root?.localStorage?.getItem(name)) { return root.localStorage.getItem(name) - } else if (name && root?.sessionStorage?.getItem(name)) { - return root.sessionStorage.getItem(name) } else return false } diff --git a/src/fireedge/src/server/routes/api/auth/utils.js b/src/fireedge/src/server/routes/api/auth/utils.js index a3ee3c54f04..4d8371e54f4 100644 --- a/src/fireedge/src/server/routes/api/auth/utils.js +++ b/src/fireedge/src/server/routes/api/auth/utils.js @@ -201,7 +201,7 @@ const setRes = (newRes = {}) => { */ const setDates = () => { limitToken = remember - ? appConfig.session__remember_expiration || defaultRememberSessionExpiration + ? appConfig.session_remember_expiration || defaultRememberSessionExpiration : appConfig.session_expiration || defaultSessionExpiration limitExpirationReuseToken = parseInt(appConfig.session_reuse_token_time, 10) || diff --git a/src/fireedge/src/server/routes/entrypoints/App.js b/src/fireedge/src/server/routes/entrypoints/App.js index 5f73037ba65..8a43dae10a6 100644 --- a/src/fireedge/src/server/routes/entrypoints/App.js +++ b/src/fireedge/src/server/routes/entrypoints/App.js @@ -13,6 +13,8 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ +// eslint-disable-next-line node/no-deprecated-api +const { parse } = require('url') const { Router } = require('express') const { renderToString } = require('react-dom/server') const root = require('window-or-global') @@ -42,8 +44,8 @@ const router = Router() router.get('*', (req, res) => { const apps = Object.keys(defaultApps) - const appName = req.url - .split(/\//gi) + const appName = parse(req.url) + .pathname.split(/\//gi) .filter((sub) => sub?.length > 0) .find((resource) => apps.includes(resource))