mirror of
https://github.com/strapi/strapi.git
synced 2025-08-11 10:18:28 +00:00
Fix subscriptions on unmount
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
fb9d4d439f
commit
11ad6abfef
@ -6,6 +6,8 @@ import hasPermissions from '../../utils/hasPermissions';
|
|||||||
import LoadingIndicatorPage from '../LoadingIndicatorPage';
|
import LoadingIndicatorPage from '../LoadingIndicatorPage';
|
||||||
|
|
||||||
const CheckPagePermissions = ({ permissions, children }) => {
|
const CheckPagePermissions = ({ permissions, children }) => {
|
||||||
|
const abortController = new AbortController();
|
||||||
|
const { signal } = abortController;
|
||||||
const userPermissions = useUser();
|
const userPermissions = useUser();
|
||||||
const [state, setState] = useState({ isLoading: true, canAccess: false });
|
const [state, setState] = useState({ isLoading: true, canAccess: false });
|
||||||
const isMounted = useRef(true);
|
const isMounted = useRef(true);
|
||||||
@ -15,7 +17,7 @@ const CheckPagePermissions = ({ permissions, children }) => {
|
|||||||
try {
|
try {
|
||||||
setState({ isLoading: true, canAccess: false });
|
setState({ isLoading: true, canAccess: false });
|
||||||
|
|
||||||
const canAccess = await hasPermissions(userPermissions, permissions);
|
const canAccess = await hasPermissions(userPermissions, permissions, signal);
|
||||||
|
|
||||||
if (isMounted.current) {
|
if (isMounted.current) {
|
||||||
setState({ isLoading: false, canAccess });
|
setState({ isLoading: false, canAccess });
|
||||||
@ -33,6 +35,10 @@ const CheckPagePermissions = ({ permissions, children }) => {
|
|||||||
|
|
||||||
checkPermission();
|
checkPermission();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
abortController.abort();
|
||||||
|
};
|
||||||
|
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [permissions]);
|
}, [permissions]);
|
||||||
|
|
||||||
|
@ -11,13 +11,15 @@ const CheckPermissions = ({ permissions, children }) => {
|
|||||||
const userPermissions = useUser();
|
const userPermissions = useUser();
|
||||||
const [state, setState] = useState({ isLoading: true, canAccess: false });
|
const [state, setState] = useState({ isLoading: true, canAccess: false });
|
||||||
const isMounted = useRef(true);
|
const isMounted = useRef(true);
|
||||||
|
const abortController = new AbortController();
|
||||||
|
const { signal } = abortController;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const checkPermission = async () => {
|
const checkPermission = async () => {
|
||||||
try {
|
try {
|
||||||
setState({ isLoading: true, canAccess: false });
|
setState({ isLoading: true, canAccess: false });
|
||||||
|
|
||||||
const canAccess = await hasPermissions(userPermissions, permissions);
|
const canAccess = await hasPermissions(userPermissions, permissions, signal);
|
||||||
|
|
||||||
if (isMounted.current) {
|
if (isMounted.current) {
|
||||||
setState({ isLoading: false, canAccess });
|
setState({ isLoading: false, canAccess });
|
||||||
@ -33,6 +35,10 @@ const CheckPermissions = ({ permissions, children }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
checkPermission();
|
checkPermission();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
abortController.abort();
|
||||||
|
};
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [permissions]);
|
}, [permissions]);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user