ra-core
Version:
Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React
45 lines • 1.67 kB
TypeScript
import { UseQueryOptions } from 'react-query';
interface State {
isLoading: boolean;
authenticated?: boolean;
}
/**
* Hook for getting the authentication status
*
* Calls the authProvider.checkAuth() method asynchronously.
*
* The return value updates according to the authProvider request state:
*
* - isLoading: true just after mount, while the authProvider is being called. false once the authProvider has answered.
* - authenticated: true while loading. then true or false depending on the authProvider response.
*
* To avoid rendering a component and force waiting for the authProvider response, use the useAuthState() hook
* instead of the useAuthenticated() hook.
*
* You can render different content depending on the authenticated status.
*
* @see useAuthenticated()
*
* @param {Object} params Any params you want to pass to the authProvider
*
* @param {Boolean} logoutOnFailure: Optional. Whether the user should be logged out if the authProvider fails to authenticate them. False by default.
*
* @returns The current auth check state. Destructure as { authenticated, error, isLoading }.
*
* @example
* import { useAuthState, Loading } from 'react-admin';
*
* const MyPage = () => {
* const { isLoading, authenticated } = useAuthState();
* if (isLoading) {
* return <Loading />;
* }
* if (authenticated) {
* return <AuthenticatedContent />;
* }
* return <AnonymousContent />;
* };
*/
declare const useAuthState: (params?: any, logoutOnFailure?: boolean, queryOptions?: UseQueryOptions<boolean, any>) => State;
export default useAuthState;
//# sourceMappingURL=useAuthState.d.ts.map