pos-dashboard/src/components/ProtectedRoute.jsx
2025-08-03 11:14:55 +07:00

18 lines
553 B
JavaScript

import { useSelector } from 'react-redux';
import { Navigate } from 'react-router-dom';
const ProtectedRoute = ({ children }) => {
// Check if user is authenticated using Redux state
const authState = useSelector((state) => state.auth);
const isAuthenticated = authState?.isAuthenticated || authState?.token;
if (!isAuthenticated) {
// Redirect to login page if not authenticated
return <Navigate to="/signin" replace />;
}
// If authenticated, render the protected component
return children;
};
export default ProtectedRoute;