Update store/routes

This commit is contained in:
jeffvli
2022-10-24 22:20:35 -07:00
parent f8e7d02daf
commit 8973571147
10 changed files with 418 additions and 293 deletions
+17
View File
@@ -0,0 +1,17 @@
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 />;
};