From 0ab6307789035732ed7b687eae78a4f68aa913a8 Mon Sep 17 00:00:00 2001 From: skywalker Date: Thu, 29 Aug 2024 22:21:07 +0300 Subject: [PATCH] fix(catalogue): do not request favorite when jwt token expired --- .../shared/instrument-card-actions/ui/Favorite.button.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/src/shared/instrument-card-actions/ui/Favorite.button.tsx b/client/src/shared/instrument-card-actions/ui/Favorite.button.tsx index 6799d201..a77111d4 100644 --- a/client/src/shared/instrument-card-actions/ui/Favorite.button.tsx +++ b/client/src/shared/instrument-card-actions/ui/Favorite.button.tsx @@ -26,9 +26,6 @@ export const FavoriteButton = (props: Props) => { const [favorite, setFavorite] = useState(); useEffect(() => { - if (jwt.current === undefined) { - return; - } const fetchFavorite = async () => { const favoriteRequest = await listFavorite.listFavorite({ withCredentials: true, @@ -44,6 +41,10 @@ export const FavoriteButton = (props: Props) => { setFavorite(favoriteRawIds.includes(instrumentId)); }; + const jwt = Jwt.extractFromCookie(); + if (jwt === null || jwt.expired()) { + return; + } fetchFavorite(); }, []);