From 2d538a0f20ca74af4d24fc2cd2a30f1826c9fa8f Mon Sep 17 00:00:00 2001 From: inmake Date: Fri, 21 Mar 2025 14:19:50 +0500 Subject: [PATCH] upd --- src/pages/ProtectedPage.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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;