mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-16 05:36:00 +02:00
18 lines
463 B
TypeScript
18 lines
463 B
TypeScript
import { Navigate, Outlet, useLocation } from 'react-router-dom';
|
|
import { useAuthStore } from '../store';
|
|
|
|
interface AuthOutletProps {
|
|
redirectTo: string;
|
|
}
|
|
|
|
export const AuthOutlet = ({ redirectTo }: AuthOutletProps) => {
|
|
const location = useLocation();
|
|
const isAuthenticated = useAuthStore((state) => !!state.accessToken);
|
|
|
|
if (isAuthenticated) {
|
|
return <Navigate replace state={{ from: location }} to={redirectTo} />;
|
|
}
|
|
|
|
return <Outlet />;
|
|
};
|