diff --git a/src/frontend/src/functions/auth.tsx b/src/frontend/src/functions/auth.tsx index 8fd807e6a5..35a6baadee 100644 --- a/src/frontend/src/functions/auth.tsx +++ b/src/frontend/src/functions/auth.tsx @@ -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); } diff --git a/src/frontend/src/views/MainView.tsx b/src/frontend/src/views/MainView.tsx index 56c2bb77e6..c874ae7288 100644 --- a/src/frontend/src/views/MainView.tsx +++ b/src/frontend/src/views/MainView.tsx @@ -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