From 0be0abaf9a6142c9dd282d1871a7da7fd207db02 Mon Sep 17 00:00:00 2001 From: ALi Josheghani Date: Wed, 30 Oct 2024 11:32:48 +0330 Subject: [PATCH] refactor: Update useAxios to include Shop-ID header This commit updates the useAxios hook to include the Shop-ID header in the request configuration. It retrieves the shop ID from the state and adds it to the headers if it exists. This change ensures that the Shop-ID is sent along with the request when making API calls. Co-authored-by: [Author Name] --- src/hooks/useAxios.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/hooks/useAxios.ts b/src/hooks/useAxios.ts index c7bb626..792da85 100644 --- a/src/hooks/useAxios.ts +++ b/src/hooks/useAxios.ts @@ -16,9 +16,16 @@ const useAxios = () => { (config) => { const state = store.getState(); const token = state.token.token; + const shopId = state.shop_id?.shop_id; + if (token) { config.headers.Authorization = `Bearer ${token}`; } + + if (shopId) { + config.headers["Shop-ID"] = shopId; + } + return config; }, (error) => { @@ -32,8 +39,8 @@ const useAxios = () => { }, (error) => { if (error.response && error.response.status === 401) { - store.dispatch(setToken('')); - navigate('/login'); + store.dispatch(setToken("")); + navigate("/login"); } return Promise.reject(error); }