import { useCallback } from 'react' ; import useAuthProvider , { defaultAuthParams } from './useAuthProvider' ; import useLogout from './useLogout' ; import useNotify from '../sideEffect/useNotify' ; see useAuthenticated see useAuthState returns { Function } example const useCheckAuth = ( ) : CheckAuth => { const authProvider = useAuthProvider ( ) ; const notify = useNotify ( ) ; const logout = useLogout ( ) ; const checkAuth = useCallback ( ( params = { } , logoutOnFailure = true , redirectTo = defaultAuthParams . loginUrl , disableNotification = false ) => authProvider . checkAuth ( params ) . catch ( error => { if ( logoutOnFailure ) { logout ( { } , error && error . redirectTo ? error . redirectTo : redirectTo ) ; const shouldSkipNotify = disableNotification || ( error && error . message === false ) ; ! shouldSkipNotify && notify ( getErrorMessage ( error , 'ra.auth.auth_check_error' ) , { type : 'warning' } ) ; } throw error ; } ) , [ authProvider , logout , notify ] ) ; return authProvider ? checkAuth : checkAuthWithoutAuthProvider ; } ; const checkAuthWithoutAuthProvider = ( ) => Promise . resolve ( ) ; param { Object } params param { boolean } logoutOnFailure param { string } redirectTo param { boolean } disableNotification return { Promise } type CheckAuth = ( params ? : any , logoutOnFailure ? : boolean , redirectTo ? : string , deprecated disableNotification ? : boolean ) => Promise < any > ; const getErrorMessage = ( error , defaultMessage ) => typeof error === 'string' ? error : typeof error === 'undefined' || ! error . message ? defaultMessage : error . message ; export default useCheckAuth ;