fix: opening auth only pages, without auth

now they are redirecting to the login page in that case
This commit is contained in:
Kentai Radiquum 2024-08-04 14:14:52 +05:00
parent 9e65838569
commit d28011b4fb
Signed by: Radiquum
GPG key ID: 858E8EE696525EED
6 changed files with 64 additions and 26 deletions

View file

@ -7,6 +7,7 @@ import { useScrollPosition } from "#/hooks/useScrollPosition";
import { useUserStore } from "../store/auth";
import { ENDPOINTS } from "#/api/config";
import { Button } from "flowbite-react";
import { useRouter } from "next/navigation";
const fetcher = async (url: string) => {
const res = await fetch(url);
@ -24,7 +25,9 @@ const fetcher = async (url: string) => {
export function HistoryPage() {
const token = useUserStore((state) => state.token);
const authState = useUserStore((state) => state.state);
const [isLoadingEnd, setIsLoadingEnd] = useState(false);
const router = useRouter();
const getKey = (pageIndex: number, previousPageData: any) => {
if (previousPageData && !previousPageData.content.length) return null;
@ -58,6 +61,12 @@ export function HistoryPage() {
}
}, [scrollPosition]);
useEffect(() => {
if (authState === "finished" && !token) {
router.push("/login");
}
}, [authState, token]);
return (
<main className="container pt-2 pb-16 mx-auto sm:pt-4 sm:pb-4">
{content && content.length > 0 ? (