From 174abfafbee5e0f63ac28c53a3745b0353879241 Mon Sep 17 00:00:00 2001 From: Nastya Date: Sat, 16 Aug 2025 07:30:26 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=8B=D0=BA=D0=B8=D0=B4=D1=8B=D0=B2?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=20=D0=BD=D0=B5=D0=B0=D0=B2=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D0=BE=D0=B3=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.tsx | 42 ++++++++++++++--------------- src/pages/Landing/HeaderLanding.tsx | 7 +++++ src/stores/user.ts | 13 ++++++++- src/ui_kit/PrivateRoute.tsx | 25 ++++++++++++++++- 4 files changed, 64 insertions(+), 23 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 78bf452b..46663509 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -277,31 +277,10 @@ export default function App() { path="/gallery" element={} />} /> - } - fallback={} - /> - } - /> - } />} - /> } />} /> - } />} - /> - } />} - /> } />} @@ -333,6 +312,27 @@ export default function App() { } /> ))} + } + fallback={} + /> + } + /> + } />} + /> + } />} + /> + } />} + /> diff --git a/src/pages/Landing/HeaderLanding.tsx b/src/pages/Landing/HeaderLanding.tsx index 0e4ef635..4d30cf6f 100644 --- a/src/pages/Landing/HeaderLanding.tsx +++ b/src/pages/Landing/HeaderLanding.tsx @@ -26,6 +26,12 @@ export default function Component() { const userId = useUserStore((state) => state.userId); const location = useLocation(); + console.log("HeaderLanding debug:", { + userId, + location: location.pathname, + backgroundLocation: location.state?.backgroundLocation + }); + return ( console.log("Signin button clicked")} sx={{ color: "black", border: "1px solid black", diff --git a/src/stores/user.ts b/src/stores/user.ts index 4de52d83..f626f241 100644 --- a/src/stores/user.ts +++ b/src/stores/user.ts @@ -66,7 +66,18 @@ export const setUser = (user: User) => }), ); -export const clearUserData = () => useUserStore.setState({ ...initialState }); +export const clearUserData = () => { + console.log("clearUserData: Clearing user data"); + console.log("clearUserData: Before clearing -", useUserStore.getState()); + + useUserStore.setState({ ...initialState }); + + console.log("clearUserData: After clearing -", useUserStore.getState()); + + // Также очищаем localStorage напрямую + localStorage.removeItem("user"); + console.log("clearUserData: localStorage cleared"); +}; export const setUserAccount = (userAccount: OriginalUserAccount) => useUserStore.setState({ userAccount }); diff --git a/src/ui_kit/PrivateRoute.tsx b/src/ui_kit/PrivateRoute.tsx index 558ea94e..27c4503d 100644 --- a/src/ui_kit/PrivateRoute.tsx +++ b/src/ui_kit/PrivateRoute.tsx @@ -1,8 +1,31 @@ import { useUserStore } from "@root/user"; import { Navigate, Outlet } from "react-router-dom"; +import { useEffect } from "react"; export default function PrivateRoute() { const user = useUserStore((state) => state.user); + const userId = useUserStore((state) => state.userId); - return user ? : ; + console.log("PrivateRoute debug:", { + user: user ? "exists" : "null", + userId: user?._id, + userIdFromStore: userId, + currentPath: window.location.pathname, + userObject: user + }); + + useEffect(() => { + if (!user) { + console.log("PrivateRoute: User is null, redirecting to / via useEffect"); + window.location.href = "/"; + } + }, [user]); + + if (!user) { + console.log("PrivateRoute: User is null, showing fallback"); + return <>; + } + + console.log("PrivateRoute: User exists, rendering Outlet"); + return ; }