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

@ -9,6 +9,13 @@ import { Dropdown, Button } from "flowbite-react";
import { sort } from "./common";
import { ENDPOINTS } from "#/api/config";
import { BookmarksList } from "#/api/utils";
import { useRouter } from "next/navigation";
const DropdownTheme = {
floating: {
target: "w-fit md:min-w-[256px]",
},
};
const fetcher = async (url: string) => {
const res = await fetch(url);
@ -26,8 +33,10 @@ const fetcher = async (url: string) => {
export function BookmarksCategoryPage(props: any) {
const token = useUserStore((state) => state.token);
const authState = useUserStore((state) => state.state);
const [selectedSort, setSelectedSort] = useState(0);
const [isLoadingEnd, setIsLoadingEnd] = useState(false);
const router = useRouter();
const getKey = (pageIndex: number, previousPageData: any) => {
if (previousPageData && !previousPageData.content.length) return null;
@ -63,12 +72,11 @@ export function BookmarksCategoryPage(props: any) {
}
}, [scrollPosition]);
const DropdownTheme = {
floating: {
target:
"w-fit bg-blue-600 enabled:hover:bg-blue-700 focus:ring-4 focus:outline-none focus:ring-blue-300 text-center dark:bg-blue-600 dark:enabled:hover:bg-blue-700 dark:focus:ring-blue-800",
},
};
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-0">
@ -80,6 +88,7 @@ export function BookmarksCategoryPage(props: any) {
label={sort.values[selectedSort].name}
dismissOnClick={true}
arrowIcon={false}
color={"blue"}
theme={DropdownTheme}
>
{sort.values.map((item, index) => (