account and protected router
This commit is contained in:
12
src/components/router/ProtectedRoute.tsx
Normal file
12
src/components/router/ProtectedRoute.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
// src/routes/ProtectedRoute.tsx
|
||||
import { Navigate, Outlet } from 'react-router-dom';
|
||||
import { useAppSelector } from '../../redux/hooks';
|
||||
|
||||
export default function ProtectedRoute() {
|
||||
const isAuthenticated = useAppSelector((state) => !!state.auth.jwt);
|
||||
if (!isAuthenticated) {
|
||||
return <Navigate to="/home/login" replace />;
|
||||
}
|
||||
|
||||
return <Outlet />;
|
||||
}
|
||||
Reference in New Issue
Block a user