You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`import useAuth from "app/hooks/useAuth";
import { Navigate, useLocation } from "react-router-dom";
import routes from "app/routes";
//import {flat} from 'react'
[eslint]
src/app/auth/AuthGuard.jsx
Line 19:22: 'flat' is not defined no-undef
Line 19:27: 'routes' is not defined no-undef
Search for the keywords to learn more about each error.
ERROR in [eslint]
src/app/auth/AuthGuard.jsx
Line 19:22: 'flat' is not defined no-undef
Line 19:27: 'routes' is not defined no-undef
Search for the keywords to learn more about each error.
webpack compiled with 1 error`
im a pro user, please support
The text was updated successfully, but these errors were encountered:
`import useAuth from "app/hooks/useAuth";
import { Navigate, useLocation } from "react-router-dom";
// const userHasPermission = (pathname, user, routes) => {
// if (!user) {
// return false;
// }
// const matched = routes.find((r) => r.path === pathname);
// const authenticated =
// matched && matched.auth && matched.auth.length ? matched.auth.includes(user.role) : true;
// return authenticated;
// };
const AuthGuard = ({ children }) => {
const { pathname } = useLocation();
const { isAuthenticated } = useAuth();
// const flatRoutes = flat(routes);
// const hasPermission = userHasPermission(pathname, user, routes);
// let authenticated = isAuthenticated && hasPermission;
// // IF YOU NEED ROLE BASED AUTHENTICATION,
// // UNCOMMENT ABOVE LINES
// // AND COMMENT OUT BELOW authenticated VARIABLE
if (isAuthenticated) return <>{children}</>;
return <Navigate replace to="/session/signin" state={{ from: pathname }} />;
};`
export default AuthGuard;
changed to
`import useAuth from "app/hooks/useAuth";
import { Navigate, useLocation } from "react-router-dom";
import routes from "app/routes";
//import {flat} from 'react'
const userHasPermission = (pathname, user, routes) => {
if (!user) {
return false;
}
const matched = routes.find((r) => r.path === pathname);
const authenticated =
matched && matched.auth && matched.auth.length ? matched.auth.includes(user.role) : true;
return authenticated;
};
export default function AuthGuard({ children }) {
const { pathname } = useLocation();
const { isAuthenticated,user } = useAuth();
const flatRoutes = flat(routes);
// // IF YOU NEED ROLE BASED AUTHENTICATION,
// // UNCOMMENT ABOVE LINES
// // AND COMMENT OUT BELOW authenticated VARIABLE
if (authenticated) return <>{children}</>;
return <Navigate replace to="/session/signin" state={{ from: pathname }} />;
}`
issue
`Failed to compile.
[eslint]
src/app/auth/AuthGuard.jsx
Line 19:22: 'flat' is not defined no-undef
Line 19:27: 'routes' is not defined no-undef
Search for the keywords to learn more about each error.
ERROR in [eslint]
src/app/auth/AuthGuard.jsx
Line 19:22: 'flat' is not defined no-undef
Line 19:27: 'routes' is not defined no-undef
Search for the keywords to learn more about each error.
webpack compiled with 1 error`
im a pro user, please support
The text was updated successfully, but these errors were encountered: