diff --git a/packages/volto/src/components/theme/Login/Login.jsx b/packages/volto/src/components/theme/Login/Login.jsx index 993efeb86a..efdc409e21 100644 --- a/packages/volto/src/components/theme/Login/Login.jsx +++ b/packages/volto/src/components/theme/Login/Login.jsx @@ -25,7 +25,6 @@ import { toast } from 'react-toastify'; import { Toast } from '@plone/volto/components'; import aheadSVG from '@plone/volto/icons/ahead.svg'; import clearSVG from '@plone/volto/icons/clear.svg'; -import { useUser } from '@plone/volto/hooks'; const messages = defineMessages({ login: { @@ -86,9 +85,6 @@ const Login = (props) => { const previousToken = usePrevious(token); - // Get user and place their data in the Redux store - useUser(); - useEffect(() => { if (location?.state?.isLogout) { // Execute a true Logout action diff --git a/packages/volto/src/hooks/user/useUser.js b/packages/volto/src/hooks/user/useUser.js index 484385e02c..3232ed0a8e 100644 --- a/packages/volto/src/hooks/user/useUser.js +++ b/packages/volto/src/hooks/user/useUser.js @@ -3,20 +3,21 @@ import { useDispatch, useSelector } from 'react-redux'; import jwtDecode from 'jwt-decode'; import { getUser } from '@plone/volto/actions'; -const useFetchUser = () => { - const user = useSelector((state) => state.users?.user); +const useUser = () => { + const users = useSelector((state) => state.users); + const user = users?.user; const userId = useSelector((state) => state.userSession.token ? jwtDecode(state.userSession.token).sub : '', ); const dispatch = useDispatch(); useEffect(() => { - if (!user?.id && userId) { + if (!user?.id && users?.get.loading === false) { dispatch(getUser(userId)); } - }, [dispatch, userId, user]); + }, [dispatch, userId, user, users?.get.loading]); return user; }; -export default useFetchUser; +export default useUser;