revamp template
This commit is contained in:
18
src/auth/RequireAuth.tsx
Normal file
18
src/auth/RequireAuth.tsx
Normal file
@ -0,0 +1,18 @@
|
||||
import { Navigate, Outlet, useLocation } from 'react-router-dom';
|
||||
|
||||
import { ScreenLoader } from '@/components/loaders';
|
||||
|
||||
import { useAuthContext } from './useAuthContext';
|
||||
|
||||
const RequireAuth = () => {
|
||||
const { auth, loading } = useAuthContext();
|
||||
const location = useLocation();
|
||||
|
||||
if (loading) {
|
||||
return <ScreenLoader />;
|
||||
}
|
||||
|
||||
return auth ? <Outlet /> : <Navigate to="/auth/login" state={{ from: location }} replace />;
|
||||
};
|
||||
|
||||
export { RequireAuth };
|
||||
Reference in New Issue
Block a user