File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
packages/ra-core/src/auth Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,34 @@ describe('<Authenticated>', () => {
2626 ) ;
2727 await screen . findByText ( 'Loading' ) ;
2828 } ) ;
29+
30+ it ( 'should not render its child when checkAuth raises an error' , async ( ) => {
31+ const NeverDisplayedComponent = jest . fn ( ( ) => (
32+ < div > It should not be called</ div >
33+ ) ) ;
34+
35+ const authProvider = {
36+ checkAuth : jest . fn ( ) . mockRejectedValue ( undefined ) ,
37+ logout : jest . fn ( ) . mockResolvedValue ( undefined ) ,
38+ } as any ;
39+
40+ render (
41+ < CoreAdminContext authProvider = { authProvider } >
42+ < Authenticated >
43+ < NeverDisplayedComponent />
44+ </ Authenticated >
45+ </ CoreAdminContext >
46+ ) ;
47+
48+ // Ensure that the NeverDisplayedComponent is not called
49+ await waitFor ( ( ) => {
50+ // Ensure that checkAuth and logout were called as expected
51+ expect ( authProvider . checkAuth ) . toHaveBeenCalled ( ) ;
52+ expect ( authProvider . logout ) . toHaveBeenCalled ( ) ;
53+ expect ( NeverDisplayedComponent ) . toHaveBeenCalledTimes ( 0 ) ;
54+ } ) ;
55+ } ) ;
56+
2957 it ( 'should render its child when authenticated' , async ( ) => {
3058 const authProvider = {
3159 login : ( ) => Promise . reject ( 'bad method' ) ,
Original file line number Diff line number Diff line change @@ -35,9 +35,9 @@ export const Authenticated = (props: AuthenticatedProps) => {
3535 const { authParams, loading = null , children } = props ;
3636
3737 // this hook will redirect to login if the user is not authenticated
38- const { isPending } = useAuthenticated ( { params : authParams } ) ;
38+ const { isPending, isError } = useAuthenticated ( { params : authParams } ) ;
3939
40- if ( isPending ) {
40+ if ( isPending || isError ) {
4141 return loading ;
4242 }
4343
You can’t perform that action at this time.
0 commit comments