From 58671a75eb1e84e570e9dbc497a1dc4b03b04b34 Mon Sep 17 00:00:00 2001 From: thgee Date: Thu, 15 Aug 2024 19:12:51 +0900 Subject: [PATCH 1/2] =?UTF-8?q?chore:=20=ED=8C=8C=EC=B8=A0=EC=BB=AC?= =?UTF-8?q?=EB=A0=89=EC=85=98=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EB=B9=84?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=BD=94=EB=93=9C=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pages/PartsCollection/PartsCollection.tsx | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/service/src/pages/PartsCollection/PartsCollection.tsx b/packages/service/src/pages/PartsCollection/PartsCollection.tsx index 180db6a6..f339cb57 100644 --- a/packages/service/src/pages/PartsCollection/PartsCollection.tsx +++ b/packages/service/src/pages/PartsCollection/PartsCollection.tsx @@ -10,20 +10,12 @@ import { IMyParts } from "@watermelon-clap/core/src/types"; import { getAccessToken } from "@watermelon-clap/core/src/utils"; export const PartsCollection = () => { - const { getIsLogin, login, reLogin } = useAuth(); + const { getIsLogin, login, handleTokenError } = useAuth(); const [equippedPartsImg, setEquippedPartsImg] = useState(); - const getPartsData = async () => { - try { - return await apiGetMyParts(); - } catch (error: any) { - if (error.message === "403") { - reLogin().then(() => refetch()); - } - throw error; - } - }; + const getPartsData = () => + apiGetMyParts().catch(handleTokenError) as Promise; const { data: partsDatas, refetch } = useQuery({ queryKey: ["myParts", getAccessToken()], From 46a4fa1aa38294a10120307afe318b28fa541aa9 Mon Sep 17 00:00:00 2001 From: thgee Date: Thu, 15 Aug 2024 22:30:51 +0900 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20`handleTokenError`=EC=9D=98=20`err?= =?UTF-8?q?or=20status`=20=EB=A7=A4=EC=A7=81=EB=84=98=EB=B2=84=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/hooks/useAuth.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/src/hooks/useAuth.ts b/packages/core/src/hooks/useAuth.ts index f07c5ba1..1fde9e61 100644 --- a/packages/core/src/hooks/useAuth.ts +++ b/packages/core/src/hooks/useAuth.ts @@ -47,7 +47,8 @@ export const useAuth = () => { * API 호출 후 catch에서 받아온 Error 객체를 인자로 넣어주세요 */ const handleTokenError = async (error: Error) => { - if (error.message === "403") { + const TOKEN_ERROR_STATUS = "403"; + if (error.message === TOKEN_ERROR_STATUS) { await reLogin(); location.reload(); } else {