ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
42 lines • 1.3 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useAuthenticated = void 0;
const useAuthState_1 = __importDefault(require("./useAuthState.cjs"));
/**
* Restrict access to authenticated users.
* Redirect anonymous users to the login page.
*
* Use it in your custom page components to require
* authentication.
*
* You can set additional `authParams` at will if your authProvider
* requires it.
*
* @example
* import { Admin, CustomRoutes, useAuthenticated } from 'react-admin';
*
* const FooPage = () => {
* const { isPending } = useAuthenticated();
* if (isPending) return null;
* return <Foo />;
* }
*
* const customRoutes = [
* <Route path="/foo" element={<FooPage />} />
* ];
*
* const App = () => (
* <Admin>
* <CustomRoutes>{customRoutes}</CustomRoutes>
* </Admin>
* );
*/
const useAuthenticated = ({ params, logoutOnFailure = true, ...options } = {}) => {
return (0, useAuthState_1.default)(params ?? emptyParams, logoutOnFailure, options);
};
exports.useAuthenticated = useAuthenticated;
const emptyParams = {};
//# sourceMappingURL=useAuthenticated.js.map