-
-
Notifications
You must be signed in to change notification settings - Fork 724
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fetch user before pass it to the restricted function (#6293)
- Loading branch information
Showing
7 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fetch `user` before pass it to the `restricted` function of the block settings. @wesleybl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fetch `user` before pass it to the `restricted` function of the block settings. @wesleybl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as useClipboard } from '@plone/volto/hooks/clipboard/useClipboard'; | ||
export { useClient } from '@plone/volto/hooks/client/useClient'; | ||
export { default as useUser } from '@plone/volto/hooks/user/useUser'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useEffect } from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import jwtDecode from 'jwt-decode'; | ||
import { getUser } from '@plone/volto/actions'; | ||
|
||
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 && users?.get.loading === false) { | ||
dispatch(getUser(userId)); | ||
} | ||
}, [dispatch, userId, user, users?.get.loading]); | ||
|
||
return user; | ||
}; | ||
|
||
export default useUser; |