20 lines
506 B
TypeScript
20 lines
506 B
TypeScript
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();
|
|
|
|
// console.log('RequireAuth render: loading =', loading, ' auth =', auth);
|
|
|
|
if (loading) {
|
|
return <ScreenLoader />;
|
|
}
|
|
|
|
return auth ? <Outlet /> : <Navigate to="/auth/login" replace />;
|
|
};
|
|
|
|
export { RequireAuth }; |