выкидывает неавторизованного

This commit is contained in:
Nastya 2025-08-16 07:30:26 +03:00
parent a6a89b0bd3
commit 174abfafbe
4 changed files with 64 additions and 23 deletions

@ -277,31 +277,10 @@ export default function App() {
path="/gallery"
element={<LazyLoading children={<QuizGallery />} />}
/>
<Route
path="/list"
element={
<LazyLoading
children={<MyQuizzesFull />}
fallback={<ListPageDummy />}
/>
}
/>
<Route
path={"/view/:quizId"}
element={<LazyLoading children={<ViewPage />} />}
/>
<Route
path={"/tariffs"}
element={<LazyLoading children={<Tariffs />} />}
/>
<Route
path={"/analytics"}
element={<LazyLoading children={<Analytics />} />}
/>
<Route
path={"/results/:quizId"}
element={<LazyLoading children={<QuizAnswersPage />} />}
/>
<Route
path={"/qaz"}
element={<LazyLoading children={<InfoPrivilege />} />}
@ -333,6 +312,27 @@ export default function App() {
}
/>
))}
<Route
path="/list"
element={
<LazyLoading
children={<MyQuizzesFull />}
fallback={<ListPageDummy />}
/>
}
/>
<Route
path={"/view/:quizId"}
element={<LazyLoading children={<ViewPage />} />}
/>
<Route
path={"/analytics"}
element={<LazyLoading children={<Analytics />} />}
/>
<Route
path={"/results/:quizId"}
element={<LazyLoading children={<QuizAnswersPage />} />}
/>
</Route>
</Routes>

@ -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 (
<SectionStyled
tag={"header"}
@ -77,6 +83,7 @@ export default function Component() {
to={"/signin"}
state={{ backgroundLocation: location }}
variant="outlined"
onClick={() => console.log("Signin button clicked")}
sx={{
color: "black",
border: "1px solid black",

@ -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 });

@ -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 ? <Outlet /> : <Navigate to="/" replace />;
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 <Outlet />;
}