Skip to content

Commit b19c1c9

Browse files
committed
Fix infinite redirection loop in useHandleCallback
1 parent e05a6c0 commit b19c1c9

2 files changed

Lines changed: 0 additions & 59 deletions

File tree

packages/ra-core/src/auth/useHandleAuthCallback.spec.tsx

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -98,50 +98,6 @@ describe('useHandleAuthCallback', () => {
9898
});
9999
});
100100

101-
it('should logout and not redirect to any page when the callback was not successfully handled', async () => {
102-
const history = createMemoryHistory({ initialEntries: ['/'] });
103-
render(
104-
<HistoryRouter history={history}>
105-
<AuthContext.Provider
106-
value={{
107-
...authProvider,
108-
handleCallback: () => Promise.reject(),
109-
}}
110-
>
111-
<QueryClientProvider client={queryClient}>
112-
<TestComponent />
113-
</QueryClientProvider>
114-
</AuthContext.Provider>
115-
</HistoryRouter>
116-
);
117-
await waitFor(() => {
118-
expect(logout).toHaveBeenCalled();
119-
expect(redirect).not.toHaveBeenCalled();
120-
});
121-
});
122-
123-
it('should redirect to the provided route when the callback was not successfully handled', async () => {
124-
const history = createMemoryHistory({ initialEntries: ['/'] });
125-
render(
126-
<HistoryRouter history={history}>
127-
<AuthContext.Provider
128-
value={{
129-
...authProvider,
130-
handleCallback: () =>
131-
Promise.reject({ redirectTo: '/test' }),
132-
}}
133-
>
134-
<QueryClientProvider client={queryClient}>
135-
<TestComponent />
136-
</QueryClientProvider>
137-
</AuthContext.Provider>
138-
</HistoryRouter>
139-
);
140-
await waitFor(() => {
141-
expect(redirect).toHaveBeenCalledWith('/test');
142-
});
143-
});
144-
145101
it('should use custom useQuery options such as onError', async () => {
146102
const history = createMemoryHistory({ initialEntries: ['/'] });
147103
render(

packages/ra-core/src/auth/useHandleAuthCallback.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useLocation } from 'react-router';
33
import { useRedirect } from '../routing';
44
import { AuthProvider, AuthRedirectResult } from '../types';
55
import useAuthProvider from './useAuthProvider';
6-
import useLogout from './useLogout';
76

87
/**
98
* This hook calls the `authProvider.handleCallback()` method on mount. This is meant to be used in a route called
@@ -17,7 +16,6 @@ export const useHandleAuthCallback = (
1716
) => {
1817
const authProvider = useAuthProvider();
1918
const redirect = useRedirect();
20-
const logout = useLogout();
2119
const location = useLocation();
2220
const locationState = location.state as any;
2321
const nextPathName = locationState && locationState.nextPathname;
@@ -46,19 +44,6 @@ export const useHandleAuthCallback = (
4644

4745
redirect(redirectTo ?? defaultRedirectUrl);
4846
},
49-
onError: err => {
50-
const { redirectTo = false, logoutOnFailure = true } = (err ??
51-
{}) as AuthRedirectResult;
52-
53-
if (logoutOnFailure) {
54-
logout({}, redirectTo);
55-
}
56-
if (redirectTo === false) {
57-
return;
58-
}
59-
60-
redirect(redirectTo);
61-
},
6247
...options,
6348
}
6449
);

0 commit comments

Comments
 (0)