mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-17 04:25:42 +00:00
make calls more robust
This commit is contained in:
@ -316,13 +316,13 @@ export function authApi(
|
|||||||
method: 'get' | 'post' | 'put' | 'delete' = 'get',
|
method: 'get' | 'post' | 'put' | 'delete' = 'get',
|
||||||
data?: any
|
data?: any
|
||||||
) {
|
) {
|
||||||
const [session] = useUserState((state) => [state.session]);
|
const state = useUserState.getState();
|
||||||
// extend default axios instance with session token
|
// extend default axios instance with session token
|
||||||
const requestConfig = config || {};
|
const requestConfig = config || {};
|
||||||
if (!requestConfig.headers) {
|
if (!requestConfig.headers) {
|
||||||
requestConfig.headers = {};
|
requestConfig.headers = {};
|
||||||
}
|
}
|
||||||
requestConfig.headers['X-Session-Token'] = session;
|
requestConfig.headers['X-Session-Token'] = state.session;
|
||||||
|
|
||||||
// set method
|
// set method
|
||||||
requestConfig.method = method;
|
requestConfig.method = method;
|
||||||
@ -333,5 +333,5 @@ export function authApi(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// use normal api
|
// use normal api
|
||||||
return api.post(url, requestConfig);
|
return api(url, requestConfig);
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,12 @@ export default function MainView() {
|
|||||||
const [allowMobile] = useLocalState((state) => [state.allowMobile]);
|
const [allowMobile] = useLocalState((state) => [state.allowMobile]);
|
||||||
// Set initial login status
|
// Set initial login status
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Local state initialization
|
try {
|
||||||
setApiDefaults();
|
// Local state initialization
|
||||||
|
setApiDefaults();
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Check if mobile
|
// Check if mobile
|
||||||
|
Reference in New Issue
Block a user