From d13792219ba4fd7589c6c9b285dba18f30f083ca Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Sat, 6 Jun 2026 10:56:59 +0330 Subject: [PATCH] me + unseen-count dont request if do not login --- src/app/[name]/(Main)/[id]/page.tsx | 2 +- src/app/[name]/(Main)/hooks/useMenuData.ts | 2 ++ src/app/[name]/(Profile)/profile/hooks/userProfileData.ts | 4 ++-- src/lib/api/func.ts | 5 +++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/app/[name]/(Main)/[id]/page.tsx b/src/app/[name]/(Main)/[id]/page.tsx index 6e7a7a5..751067c 100644 --- a/src/app/[name]/(Main)/[id]/page.tsx +++ b/src/app/[name]/(Main)/[id]/page.tsx @@ -132,7 +132,7 @@ function FoodPage({}: Props) {
{/* eslint-disable-next-line @next/next/no-img-element */} {foodName} { diff --git a/src/app/[name]/(Main)/hooks/useMenuData.ts b/src/app/[name]/(Main)/hooks/useMenuData.ts index 727281f..874ccae 100644 --- a/src/app/[name]/(Main)/hooks/useMenuData.ts +++ b/src/app/[name]/(Main)/hooks/useMenuData.ts @@ -1,6 +1,7 @@ import { useQuery } from "@tanstack/react-query"; import * as api from "../service/MenuService"; import { useParams } from "next/navigation"; +import { hasAuthToken } from "@/lib/api/func"; export const useGetFoods = () => { const { name } = useParams<{ name: string }>(); @@ -26,5 +27,6 @@ export const useGetNotificationsCount = () => { return useQuery({ queryKey: ["notifications-count"], queryFn: api.getNotificationsCount, + enabled: hasAuthToken(), }); }; diff --git a/src/app/[name]/(Profile)/profile/hooks/userProfileData.ts b/src/app/[name]/(Profile)/profile/hooks/userProfileData.ts index 61a2e11..85a13d6 100644 --- a/src/app/[name]/(Profile)/profile/hooks/userProfileData.ts +++ b/src/app/[name]/(Profile)/profile/hooks/userProfileData.ts @@ -1,13 +1,13 @@ import { useMutation, useQuery } from "@tanstack/react-query"; import * as api from "../service/ProfileService"; -import { getToken } from "@/lib/api/func"; +import { hasAuthToken } from "@/lib/api/func"; export const useGetProfile = () => { return useQuery({ queryKey: ["profile"], queryFn: api.getProfile, retry: false, - enabled: !!getToken(), + enabled: hasAuthToken(), }); }; diff --git a/src/lib/api/func.ts b/src/lib/api/func.ts index ad7f4f1..841b767 100644 --- a/src/lib/api/func.ts +++ b/src/lib/api/func.ts @@ -1,5 +1,10 @@ import { REFRESH_TOKEN_NAME, TOKEN_NAME } from "@/config/const"; +export const hasAuthToken = (): boolean => { + if (typeof window === "undefined") return false; + return !!localStorage.getItem(TOKEN_NAME); +}; + export const getToken = async (): Promise => { if (typeof window === "undefined") return null; return localStorage.getItem(TOKEN_NAME);