-
Notifications
You must be signed in to change notification settings - Fork 381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable user permision not working #52
Comments
how to setup RBAC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`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: