UNPKG

ra-core

Version:

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

49 lines 2.35 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useIsAuthPending = void 0; var react_query_1 = require("@tanstack/react-query"); var core_1 = require("../core"); var useAuthProvider_1 = __importDefault(require("./useAuthProvider")); /** * 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. */ var useIsAuthPending = function (params) { var action = params.action, props = __rest(params, ["action"]); var queryClient = (0, react_query_1.useQueryClient)(); var authProvider = (0, useAuthProvider_1.default)(); var resource = (0, core_1.useResourceContext)(props); if (!authProvider) { return false; } var authQueryState = queryClient.getQueryState(['auth', 'checkAuth', {}]); var canAccessQueryState = queryClient.getQueryState([ 'auth', 'canAccess', { action: action, resource: resource }, ]); if ((authQueryState === null || authQueryState === void 0 ? void 0 : authQueryState.status) === 'pending' || (authProvider.canAccess && (canAccessQueryState === null || canAccessQueryState === void 0 ? void 0 : canAccessQueryState.status) === 'pending')) { return true; } return false; }; exports.useIsAuthPending = useIsAuthPending; //# sourceMappingURL=useIsAuthPending.js.map