ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
38 lines • 1.7 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useIsAuthPending = void 0;
const react_query_1 = require("@tanstack/react-query");
const core_1 = require("../core/index.cjs");
const useAuthProvider_1 = __importDefault(require("./useAuthProvider.cjs"));
/**
* 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.
*/
const useIsAuthPending = (params) => {
const { action, ...props } = params;
const queryClient = (0, react_query_1.useQueryClient)();
const authProvider = (0, useAuthProvider_1.default)();
const resource = (0, core_1.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;
};
exports.useIsAuthPending = useIsAuthPending;
//# sourceMappingURL=useIsAuthPending.js.map