From a45b7e6f9f376526e4e382988371ff46bcb6899e Mon Sep 17 00:00:00 2001 From: Andrea Cecchi Date: Wed, 16 Oct 2024 14:50:15 +0200 Subject: [PATCH] fix: do not break LinkView for anonymous users (#786) * fix: do not break LinkView for anonymous users * Update src/customizations/volto/components/theme/View/LinkView.jsx Co-authored-by: Mauro Amico * change variable name in LinkView --------- Co-authored-by: Mauro Amico --- .../volto/components/theme/View/LinkView.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/customizations/volto/components/theme/View/LinkView.jsx b/src/customizations/volto/components/theme/View/LinkView.jsx index 53b938691..424fc19bd 100644 --- a/src/customizations/volto/components/theme/View/LinkView.jsx +++ b/src/customizations/volto/components/theme/View/LinkView.jsx @@ -13,12 +13,12 @@ import config from '@plone/volto/registry'; const LinkView = ({ token, content }) => { const history = useHistory(); - const userIsSpidUser = useSelector( - (state) => state.users.user.roles.length === 0, + const userWithoutRoles = useSelector((state) => + state.users?.user ? state.users.user?.roles?.length === 0 : true, ); useEffect(() => { - if (!token || userIsSpidUser) { + if (!token || userWithoutRoles) { const { remoteUrl } = content; if (isInternalURL(remoteUrl)) { history.replace(flattenToAppURL(remoteUrl)); @@ -26,7 +26,7 @@ const LinkView = ({ token, content }) => { window.location.href = flattenToAppURL(remoteUrl); } } - }, [content, history, token, userIsSpidUser]); + }, [content, history, token, userWithoutRoles]); const { title, description, remoteUrl } = content; const { openExternalLinkInNewTab } = config.settings; const Container =