diff --git a/src/pages/ProtectedPage.tsx b/src/pages/ProtectedPage.tsx index 6f02a6a..0020d19 100644 --- a/src/pages/ProtectedPage.tsx +++ b/src/pages/ProtectedPage.tsx @@ -1,10 +1,23 @@ import { Navigate, Outlet } from "react-router"; import useAuthStore from "../stores/useAuthStore"; +import api from "../utils/api"; +import { useQuery } from "@tanstack/react-query"; +import { IUser } from "../types/IUser"; function ProtectedPage() { const { token } = useAuthStore(); - return token ? : ; + const { data: user, isLoading } = useQuery({ + queryKey: ["me"], + queryFn: () => api.get("auth/me").json(), + enabled: !!token, + }); + + if (isLoading) { + return null; + } + + return user ? : ; } export default ProtectedPage;