1
- import useAuth from 'app/hooks/useAuth'
2
- import { Navigate , useLocation } from 'react-router-dom'
1
+ import useAuth from 'app/hooks/useAuth' ;
2
+ // import { flat } from 'app/utils/utils';
3
+ import { Navigate , useLocation } from 'react-router-dom' ;
4
+ // import AllPages from '../routes';
3
5
4
- // const getUserRoleAuthStatus = (pathname, user, routes) => {
6
+ // const userHasPermission = (pathname, user, routes) => {
5
7
// if (!user) {
6
8
// return false;
7
9
// }
@@ -13,35 +15,32 @@ import { Navigate, useLocation } from 'react-router-dom'
13
15
// };
14
16
15
17
const AuthGuard = ( { children } ) => {
16
- const { isAuthenticated } = useAuth ( )
17
- const { pathname } = useLocation ( )
18
- // const flatRoutes = flat(routes);
19
-
20
- // const isUserRoleAuthenticated = getUserRoleAuthStatus(
21
- // pathname,
22
- // user,
23
- // flatRoutes
24
- // )
25
- // let authenticated = isAuthenticated && isUserRoleAuthenticated
26
-
27
- // IF YOU NEED ROLE BASED AUTHENTICATION,
28
- // UNCOMMENT ABOVE TWO LINES, getUserRoleAuthStatus METHOD AND user VARIABLE
29
- // AND COMMENT OUT BELOW LINE
30
- // let location = useLocation()
31
-
32
- return (
33
- < >
34
- { isAuthenticated ? (
35
- children
36
- ) : (
37
- < Navigate
38
- replace
39
- to = "/session/signin"
40
- state = { { from : pathname } }
41
- />
42
- ) }
43
- </ >
44
- )
45
- }
46
-
47
- export default AuthGuard
18
+ let {
19
+ isAuthenticated,
20
+ // user
21
+ } = useAuth ( ) ;
22
+ const { pathname } = useLocation ( ) ;
23
+
24
+ // const routes = flat(AllPages);
25
+
26
+ // const hasPermission = userHasPermission(pathname, user, routes);
27
+ // let authenticated = isAuthenticated && hasPermission;
28
+
29
+ // // IF YOU NEED ROLE BASED AUTHENTICATION,
30
+ // // UNCOMMENT ABOVE LINES
31
+ // // AND COMMENT OUT BELOW authenticated VARIABLE
32
+
33
+ let authenticated = isAuthenticated ;
34
+
35
+ return (
36
+ < >
37
+ { authenticated ? (
38
+ children
39
+ ) : (
40
+ < Navigate replace to = "/session/signin" state = { { from : pathname } } />
41
+ ) }
42
+ </ >
43
+ ) ;
44
+ } ;
45
+
46
+ export default AuthGuard ;
0 commit comments