me + unseen-count dont request if do not login
This commit is contained in:
@@ -132,7 +132,7 @@ function FoodPage({}: Props) {
|
||||
<div className="relative w-full lg:h-full min-h-0 not-lg:bg-container rounded-2xl overflow-hidden lg:rounded-r-none lg:order-1">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
className="lg:object-contain h-auto object-cover bg-[#F2F2F9] w-full"
|
||||
className="lg:object-cover lg:h-full object-cover bg-[#F2F2F9] w-full"
|
||||
src={foodImage}
|
||||
alt={foodName}
|
||||
onError={(event) => {
|
||||
|
||||
@@ -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(),
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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(),
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -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<string | null> => {
|
||||
if (typeof window === "undefined") return null;
|
||||
return localStorage.getItem(TOKEN_NAME);
|
||||
|
||||
Reference in New Issue
Block a user