UNPKG

ra-core

Version:

Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React

31 lines 1.35 kB
import { useQueryClient } from '@tanstack/react-query'; import { useResourceContext } from "../core/index.js"; import useAuthProvider from "./useAuthProvider.js"; /** * A hook that returns true if the authProvider is currently checking the authentication status or the user's access rights. * @param params * @param params.action The action to check access for * @param params.resource The resource to check access for (optional). Defaults to the resource of the current ResourceContext. * @returns {boolean} true if the authProvider is currently checking the authentication status or the user's access rights, false otherwise. */ export const useIsAuthPending = (params) => { const { action, ...props } = params; const queryClient = useQueryClient(); const authProvider = useAuthProvider(); const resource = useResourceContext(props); if (!authProvider) { return false; } const authQueryState = queryClient.getQueryState(['auth', 'checkAuth', {}]); const canAccessQueryState = queryClient.getQueryState([ 'auth', 'canAccess', { action, resource }, ]); if (authQueryState?.status === 'pending' || (authProvider.canAccess && canAccessQueryState?.status === 'pending')) { return true; } return false; }; //# sourceMappingURL=useIsAuthPending.js.map