выкидывает неавторизованного
This commit is contained in:
parent
a6a89b0bd3
commit
174abfafbe
42
src/App.tsx
42
src/App.tsx
@ -277,31 +277,10 @@ export default function App() {
|
|||||||
path="/gallery"
|
path="/gallery"
|
||||||
element={<LazyLoading children={<QuizGallery />} />}
|
element={<LazyLoading children={<QuizGallery />} />}
|
||||||
/>
|
/>
|
||||||
<Route
|
|
||||||
path="/list"
|
|
||||||
element={
|
|
||||||
<LazyLoading
|
|
||||||
children={<MyQuizzesFull />}
|
|
||||||
fallback={<ListPageDummy />}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path={"/view/:quizId"}
|
|
||||||
element={<LazyLoading children={<ViewPage />} />}
|
|
||||||
/>
|
|
||||||
<Route
|
<Route
|
||||||
path={"/tariffs"}
|
path={"/tariffs"}
|
||||||
element={<LazyLoading children={<Tariffs />} />}
|
element={<LazyLoading children={<Tariffs />} />}
|
||||||
/>
|
/>
|
||||||
<Route
|
|
||||||
path={"/analytics"}
|
|
||||||
element={<LazyLoading children={<Analytics />} />}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path={"/results/:quizId"}
|
|
||||||
element={<LazyLoading children={<QuizAnswersPage />} />}
|
|
||||||
/>
|
|
||||||
<Route
|
<Route
|
||||||
path={"/qaz"}
|
path={"/qaz"}
|
||||||
element={<LazyLoading children={<InfoPrivilege />} />}
|
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>
|
</Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|
||||||
|
@ -26,6 +26,12 @@ export default function Component() {
|
|||||||
const userId = useUserStore((state) => state.userId);
|
const userId = useUserStore((state) => state.userId);
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
|
|
||||||
|
console.log("HeaderLanding debug:", {
|
||||||
|
userId,
|
||||||
|
location: location.pathname,
|
||||||
|
backgroundLocation: location.state?.backgroundLocation
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SectionStyled
|
<SectionStyled
|
||||||
tag={"header"}
|
tag={"header"}
|
||||||
@ -77,6 +83,7 @@ export default function Component() {
|
|||||||
to={"/signin"}
|
to={"/signin"}
|
||||||
state={{ backgroundLocation: location }}
|
state={{ backgroundLocation: location }}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
|
onClick={() => console.log("Signin button clicked")}
|
||||||
sx={{
|
sx={{
|
||||||
color: "black",
|
color: "black",
|
||||||
border: "1px solid 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) =>
|
export const setUserAccount = (userAccount: OriginalUserAccount) =>
|
||||||
useUserStore.setState({ userAccount });
|
useUserStore.setState({ userAccount });
|
||||||
|
@ -1,8 +1,31 @@
|
|||||||
import { useUserStore } from "@root/user";
|
import { useUserStore } from "@root/user";
|
||||||
import { Navigate, Outlet } from "react-router-dom";
|
import { Navigate, Outlet } from "react-router-dom";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
export default function PrivateRoute() {
|
export default function PrivateRoute() {
|
||||||
const user = useUserStore((state) => state.user);
|
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 />;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user