feat(web): return-to-destination on auth redirect; logout pending state (#48)
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
import { Navigate, Outlet } from "react-router-dom";
|
||||
import { Navigate, Outlet, useLocation } from "react-router-dom";
|
||||
|
||||
import { useMe } from "../api/queries";
|
||||
import { AppShellSkeleton } from "@/components/ui/skeletons";
|
||||
|
||||
export function RequireAuth() {
|
||||
const { data: user, isLoading } = useMe();
|
||||
const location = useLocation();
|
||||
|
||||
if (isLoading) return <AppShellSkeleton />;
|
||||
|
||||
if (!user) return <Navigate to="/login" replace />;
|
||||
if (!user) {
|
||||
const from = encodeURIComponent(location.pathname + location.search);
|
||||
return <Navigate to={`/login?from=${from}`} replace />;
|
||||
}
|
||||
|
||||
return <Outlet />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user