1
- import { useCheckAuth } from " ra-core" ;
2
- import { useEffect } from " react" ;
3
- import { To , useNavigate } from " react-router" ;
1
+ import { useCheckAuth } from ' ra-core' ;
2
+ import { useEffect } from ' react' ;
3
+ import { To , useNavigate } from ' react-router' ;
4
4
5
5
/**
6
6
* This hook redirect the user to the provided path (/ by default) if they are authenticated.
@@ -13,21 +13,21 @@ import { To, useNavigate } from "react-router";
13
13
* }
14
14
**/
15
15
export const useRedirectIfAuthenticated = (
16
- redirectTo : UseRedirectIfAuthenticatedOptions = "/"
16
+ redirectTo : UseRedirectIfAuthenticatedOptions = '/'
17
17
) => {
18
- const navigate = useNavigate ( ) ;
19
- const checkAuth = useCheckAuth ( ) ;
18
+ const navigate = useNavigate ( ) ;
19
+ const checkAuth = useCheckAuth ( ) ;
20
20
21
- useEffect ( ( ) => {
22
- checkAuth ( { } , false , undefined , true )
23
- . then ( ( ) => {
24
- // already authenticated, redirect to the home page
25
- navigate ( redirectTo ) ;
26
- } )
27
- . catch ( ( ) => {
28
- // not authenticated, stay on the login page
29
- } ) ;
30
- } , [ checkAuth , navigate , redirectTo ] ) ;
21
+ useEffect ( ( ) => {
22
+ checkAuth ( { } , false , undefined , true )
23
+ . then ( ( ) => {
24
+ // already authenticated, redirect to the home page
25
+ navigate ( redirectTo ) ;
26
+ } )
27
+ . catch ( ( ) => {
28
+ // not authenticated, stay on the login page
29
+ } ) ;
30
+ } , [ checkAuth , navigate , redirectTo ] ) ;
31
31
} ;
32
32
33
33
export type UseRedirectIfAuthenticatedOptions = To ;
0 commit comments