From c197a8fdd536e1f2bc93350f37fe5119a0ec1c85 Mon Sep 17 00:00:00 2001 From: Teodor Date: Tue, 5 Aug 2025 17:24:10 +0300 Subject: [PATCH 1/6] remove local storage info for anonymous --- src/index.js | 2 +- .../conditionalPersistenceMiddleware.js | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/middleware/conditionalPersistenceMiddleware.js diff --git a/src/index.js b/src/index.js index 88e8b63..51c4ef0 100644 --- a/src/index.js +++ b/src/index.js @@ -13,7 +13,7 @@ const applyConfig = (config) => { oidcLogout, oidcRedirect, }; - config.settings.persistentReducers = [...config.settings.persistentReducers, 'authomaticRedirect', 'oidcLogout', 'oidcRedirect']; + config.settings.storeExtenders = [...(config.settings.storeExtenders || []), (middlewares) => [conditionalPersistenceMiddleware, ...middlewares]]; config.settings.nonContentRoutes = [...config.settings.nonContentRoutes, /^\/login-authomatic\/.*$/, /^\/login-oidc\/.*$/]; config.addonRoutes.push( { path: '/fallback_login', component: VoltoLogin }, diff --git a/src/middleware/conditionalPersistenceMiddleware.js b/src/middleware/conditionalPersistenceMiddleware.js new file mode 100644 index 0000000..cb80fc4 --- /dev/null +++ b/src/middleware/conditionalPersistenceMiddleware.js @@ -0,0 +1,50 @@ +/** + * Conditional Persistence Middleware + * Prevents local storage initialization for authentication reducers when user is anonymous + * This addresses GDPR/EUDPR compliance requirements for the EEA website + * @module middleware/conditionalPersistenceMiddleware + */ + +const CONDITIONAL_REDUCERS = ['authomaticRedirect', 'oidcLogout', 'oidcRedirect']; + +const isUserAuthenticated = (state) => { + return !!(state?.userSession?.token || state?.users?.user?.token || state?.users?.user?.id || state?.userSession?.user?.id); +}; + +/** + * Removes auth reducer data from local storage for anonymous users + */ +const preventAnonymousLocalStorage = () => { + if (typeof window === 'undefined' || !window.localStorage) { + return; + } + + try { + CONDITIONAL_REDUCERS.forEach((reducerName) => { + const key = `redux_localstorage_simple_${reducerName}`; + if (window.localStorage.getItem(key)) { + window.localStorage.removeItem(key); + } + }); + } catch (error) { + console.debug('LocalStorage cleanup skipped:', error.message); + } +}; + +/** + * Manages conditional persistence of auth reducers in local storage + */ +const conditionalPersistenceMiddleware = (store) => (next) => (action) => { + const result = next(action); + const state = store.getState(); + const isAuthenticated = isUserAuthenticated(state); + + // Clean up local storage for anonymous users after every action + if (!isAuthenticated) { + preventAnonymousLocalStorage(); + } + + return result; +}; + +export default conditionalPersistenceMiddleware; From 2cdae291a5e413e4e45c0e470b6c5c3113ae5542 Mon Sep 17 00:00:00 2001 From: Teodor Date: Tue, 5 Aug 2025 17:31:03 +0300 Subject: [PATCH 2/6] add missing import --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 51c4ef0..68697d9 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,5 @@ import Login from './components/Login/Login'; +import conditionalPersistenceMiddleware from './middleware/conditionalPersistenceMiddleware'; import LoginAuthomatic from './components/LoginAuthomatic/LoginAuthomatic'; import LoginOIDC from './components/LoginOIDC/LoginOIDC'; import Logout from './components/Logout/Logout'; From 5e61fe95a333a92f94762b8262a7c354011e2ffb Mon Sep 17 00:00:00 2001 From: Teodor Date: Tue, 5 Aug 2025 17:41:10 +0300 Subject: [PATCH 3/6] remove console statement --- src/middleware/conditionalPersistenceMiddleware.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/middleware/conditionalPersistenceMiddleware.js b/src/middleware/conditionalPersistenceMiddleware.js index cb80fc4..99d725f 100644 --- a/src/middleware/conditionalPersistenceMiddleware.js +++ b/src/middleware/conditionalPersistenceMiddleware.js @@ -27,7 +27,6 @@ const preventAnonymousLocalStorage = () => { } }); } catch (error) { - console.debug('LocalStorage cleanup skipped:', error.message); } }; From fd1bf68b9b37604e31f281490be15b39ab32e146 Mon Sep 17 00:00:00 2001 From: Teodor Date: Tue, 5 Aug 2025 17:58:50 +0300 Subject: [PATCH 4/6] fix formating --- src/middleware/conditionalPersistenceMiddleware.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/middleware/conditionalPersistenceMiddleware.js b/src/middleware/conditionalPersistenceMiddleware.js index 99d725f..74eec87 100644 --- a/src/middleware/conditionalPersistenceMiddleware.js +++ b/src/middleware/conditionalPersistenceMiddleware.js @@ -26,8 +26,7 @@ const preventAnonymousLocalStorage = () => { window.localStorage.removeItem(key); } }); - } catch (error) { - } + } catch (error) {} }; /** From 2aedb8aab72f99a297c1ae9b26ff304c78511355 Mon Sep 17 00:00:00 2001 From: Teodor Date: Tue, 19 Aug 2025 17:05:48 +0300 Subject: [PATCH 5/6] add changelog entry --- CHANGELOG.md | 14 +++++++------- src/middleware/conditionalPersistenceMiddleware.js | 1 - 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b907ab9..527a63c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,30 +1,30 @@ # Changelog +## [2.0.2](https://github.com/collective/volto-authomatic/compare/2.0.1...2.0.2) (2025-08-19) + +### Bug Fixes + +- Remove unnecessary local storage (redux) for anonymous users (#38) - Prevents auth reducer data from being stored in local storage when users are not authenticated, improving performance and reducing unnecessary data persistence + ## [2.0.1](https://github.com/collective/volto-authomatic/compare/2.0.0...2.0.1) (2024-01-23) ## [2.0.0](https://github.com/collective/volto-authomatic/compare/1.3.0...2.0.0) (2023-11-17) - ### Features - - feat: Add support for pas.plugins.oidc (#12) ([fe191764b7f81f2c87a7618e165cfa3f23cb60aa](https://github.com/collective/volto-authomatic/commit/fe191764b7f81f2c87a7618e165cfa3f23cb60aa)) - feat: Added Spanish support ([cd760708797b3465b88b96594c77ea3811a96828](https://github.com/collective/volto-authomatic/commit/cd760708797b3465b88b96594c77ea3811a96828)) ## [1.3.0](https://github.com/collective/volto-authomatic/compare/1.2.0...1.3.0) (2022-12-05) - ### Features - - feat: Add fallback_login route pointing to the normal login form ([7cc9cffda2a0aab50f2c9729a60aeae709fca4d4](https://github.com/collective/volto-authomatic/commit/7cc9cffda2a0aab50f2c9729a60aeae709fca4d4)) ## [1.2.0](https://github.com/collective/volto-authomatic/compare/1.1.0...1.2.0) (2022-07-25) - ### Features - - feat: Apply i18n to Login and Logout views ([0c996958828e18e4d058e0fa2c8d4806297764ff](https://github.com/collective/volto-authomatic/commit/0c996958828e18e4d058e0fa2c8d4806297764ff)) - feat: Rename package to @plone-collective/volto-authomatic ([8bdd8dd1d6e7f676f05f47db449307fbd5ba026e](https://github.com/collective/volto-authomatic/commit/8bdd8dd1d6e7f676f05f47db449307fbd5ba026e)) @@ -61,4 +61,4 @@ ### Feature -- Initial release \ No newline at end of file +- Initial release diff --git a/src/middleware/conditionalPersistenceMiddleware.js b/src/middleware/conditionalPersistenceMiddleware.js index 74eec87..716de07 100644 --- a/src/middleware/conditionalPersistenceMiddleware.js +++ b/src/middleware/conditionalPersistenceMiddleware.js @@ -1,7 +1,6 @@ /** * Conditional Persistence Middleware * Prevents local storage initialization for authentication reducers when user is anonymous - * This addresses GDPR/EUDPR compliance requirements for the EEA website * @module middleware/conditionalPersistenceMiddleware */ From b08a4a3bb560e2cc7163c432f4007453fbca7abe Mon Sep 17 00:00:00 2001 From: Teodor Date: Thu, 21 Aug 2025 21:20:23 +0300 Subject: [PATCH 6/6] fix ESlint --- src/components/Login/Login.jsx | 2 +- src/components/LoginOIDC/LoginOIDC.jsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Login/Login.jsx b/src/components/Login/Login.jsx index 3e386ab..0ce3395 100644 --- a/src/components/Login/Login.jsx +++ b/src/components/Login/Login.jsx @@ -69,7 +69,7 @@ function Login({ intl }) { window.location.href = next_url; }, 500); } - }, [startedOIDC, loginOIDCValues]); + }, [startedOIDC, loginOIDCValues]); // eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { if (options !== undefined && options.length === 1 && options[0].id === 'oidc') { diff --git a/src/components/LoginOIDC/LoginOIDC.jsx b/src/components/LoginOIDC/LoginOIDC.jsx index 7f4e4c9..f071130 100644 --- a/src/components/LoginOIDC/LoginOIDC.jsx +++ b/src/components/LoginOIDC/LoginOIDC.jsx @@ -57,7 +57,7 @@ function LoginOIDC({ intl }) { toast.dismiss('loginFailed'); } } - }, [token, history]); + }, [token, history]); // eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { if (error) {