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