File size: 427 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
import { Navigate, Outlet, useLocation } from "react-router";
import { useUser } from "@/client/services/user";
export const AuthGuard = () => {
const location = useLocation();
const redirectTo = location.pathname + location.search;
const { user, loading } = useUser();
if (loading) return null;
if (user) {
return <Outlet />;
}
return <Navigate replace to={`/auth/login?redirect=${redirectTo}`} />;
};
|