From 6db6664894add35badadd50a1296eb9808a5ac77 Mon Sep 17 00:00:00 2001 From: "jason.lam" Date: Tue, 29 Apr 2025 14:02:41 +0800 Subject: [PATCH] [feature] handle 401 logic in axios --- src/components/ItemsSearch/ItemsSearch.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/components/ItemsSearch/ItemsSearch.tsx b/src/components/ItemsSearch/ItemsSearch.tsx index 404ffb1..b8a3f6a 100644 --- a/src/components/ItemsSearch/ItemsSearch.tsx +++ b/src/components/ItemsSearch/ItemsSearch.tsx @@ -85,16 +85,20 @@ const ItemsSearch: React.FC = ({ items }) => { }, [filterObj, pagingController.pageNum, pagingController.pageSize]); const refetchData = async (filterObj: SearchQuery) => { - // Make sure the API endpoint is correct + + const authHeader = axiosInstance.defaults.headers['Authorization']; + if (!authHeader) { + return; // Exit the function if the token is not set + } + const params ={ pageNum: pagingController.pageNum, pageSize: pagingController.pageSize, ...filterObj, } + try { - console.log("[debug] axiosInstance", axiosInstance) const response = await axiosInstance.get(`${NEXT_PUBLIC_API_URL}/items/getRecordByPage`, { params }); - console.log("[debug] resposne", response) setFilteredItems(response.data.records); setPagingController({ ...pagingController,