mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-09 22:02:19 +02:00
18 lines
477 B
TypeScript
18 lines
477 B
TypeScript
import { Navigate, Outlet, useLocation } from 'react-router-dom';
|
|
import { useAuthStore } from '../../store';
|
|
|
|
interface PrivateOutletProps {
|
|
redirectTo: string;
|
|
}
|
|
|
|
export const PrivateOutlet = ({ redirectTo }: PrivateOutletProps) => {
|
|
const location = useLocation();
|
|
const isAuthenticated = useAuthStore((state) => state.isAuthenticated);
|
|
|
|
if (isAuthenticated) {
|
|
return <Outlet />;
|
|
}
|
|
|
|
return <Navigate replace state={{ from: location }} to={redirectTo} />;
|
|
};
|