Files
feishin/src/renderer/router/auth-outlet.tsx
T
2022-10-24 22:20:35 -07:00

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 />;
};