This commit is contained in:
Malai Raja
2023-11-27 17:09:27 +05:30
commit 7113ac0681
223 changed files with 56261 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import PropTypes from 'prop-types';
import { useEffect } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
// project import
import useAuth from 'hooks/useAuth';
// ==============================|| AUTH GUARD ||============================== //
const AuthGuard = ({ children }) => {
const { isLoggedIn } = useAuth();
const navigate = useNavigate();
const location = useLocation();
useEffect(() => {
if (!isLoggedIn) {
navigate('login', {
state: {
from: location.pathname
},
replace: true
});
navigate('login', { replace: true });
}
}, [isLoggedIn, navigate, location]);
return children;
};
AuthGuard.propTypes = {
children: PropTypes.node
};
export default AuthGuard;

View File

@@ -0,0 +1,34 @@
import PropTypes from 'prop-types';
import { useEffect } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
// project import
import { APP_DEFAULT_PATH } from 'config';
import useAuth from 'hooks/useAuth';
// ==============================|| GUEST GUARD ||============================== //
const GuestGuard = ({ children }) => {
const { isLoggedIn } = useAuth();
const navigate = useNavigate();
const location = useLocation();
useEffect(() => {
if (isLoggedIn) {
navigate(location?.state?.from ? location?.state?.from : APP_DEFAULT_PATH, {
state: {
from: ''
},
replace: true
});
}
}, [isLoggedIn, navigate, location]);
return children;
};
GuestGuard.propTypes = {
children: PropTypes.node
};
export default GuestGuard;