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]
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user