Skip to content

Commit ee2d8e1

Browse files
committed
Fix useAuthState fails if authPRovider.checkAuth isn't async
1 parent ba4103e commit ee2d8e1

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,21 @@ const useAuthState = <ErrorType = Error>(
6262

6363
const queryResult = useQuery<boolean, any>({
6464
queryKey: ['auth', 'checkAuth', params],
65-
queryFn: ({ signal }) => {
65+
queryFn: async ({ signal }) => {
6666
// The authProvider is optional in react-admin
6767
if (!authProvider) {
6868
return true;
6969
}
70-
return authProvider
71-
.checkAuth({ ...params, signal })
72-
.then(() => true)
73-
.catch(error => {
74-
// This is necessary because react-query requires the error to be defined
75-
if (error != null) {
76-
throw error;
77-
}
78-
79-
throw new Error();
80-
});
70+
try {
71+
await authProvider.checkAuth({ ...params, signal });
72+
return true;
73+
} catch (error) {
74+
// This is necessary because react-query requires the error to be defined
75+
if (error != null) {
76+
throw error;
77+
}
78+
throw new Error();
79+
}
8180
},
8281
retry: false,
8382
...options,

0 commit comments

Comments
 (0)