import { UseQueryOptions } from 'react-query'; import useAuthState from './useAuthState'; /** * 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 'mv-tmp'; * const FooPage = () => { * useAuthenticated(); * return ; * } * const customRoutes = [ * } /> * ]; * const App = () => ( * * {customRoutes} * * ); */ export const useAuthenticated = ({ params, ...options }: UseAuthenticatedOptions = {}) => { useAuthState(params ?? emptyParams, true, options); }; export type UseAuthenticatedOptions = UseQueryOptions< boolean, any > & { params?: ParamsType; }; const emptyParams = {};