diff --git a/src/frontend/src/functions/auth.tsx b/src/frontend/src/functions/auth.tsx index c9477de5e6..77a70aff75 100644 --- a/src/frontend/src/functions/auth.tsx +++ b/src/frontend/src/functions/auth.tsx @@ -20,8 +20,8 @@ export const doClassicLogin = async (username: string, password: string) => { const token = await axios .get(apiUrl(ApiPaths.user_token), { auth: { username, password }, - baseURL: host.toString(), - timeout: 5000, + baseURL: host, + timeout: 2000, params: { name: 'inventree-web-app' } @@ -120,7 +120,7 @@ export function handleReset(navigate: any, values: { email: string }) { export function checkLoginState(navigate: any, redirect?: string) { api .get(apiUrl(ApiPaths.user_token), { - timeout: 5000, + timeout: 2000, params: { name: 'inventree-web-app' } @@ -140,8 +140,7 @@ export function checkLoginState(navigate: any, redirect?: string) { navigate('/login'); } }) - .catch((error) => { - console.error('Error fetching login information:', error); + .catch(() => { navigate('/login'); }); } diff --git a/src/frontend/src/main.tsx b/src/frontend/src/main.tsx index e0e7fd44bb..53322dc2b2 100644 --- a/src/frontend/src/main.tsx +++ b/src/frontend/src/main.tsx @@ -25,26 +25,37 @@ export const IS_DEV = import.meta.env.DEV; export const IS_DEMO = import.meta.env.VITE_DEMO === 'true'; export const IS_DEV_OR_DEMO = IS_DEV || IS_DEMO; +// Filter out any settings that are not defined +let loaded_vals = (window.INVENTREE_SETTINGS || {}) as any; +Object.keys(loaded_vals).forEach((key) => { + if (loaded_vals[key] === undefined) { + delete loaded_vals[key]; + // check for empty server list + } else if (key === 'server_list' && loaded_vals[key].length === 0) { + delete loaded_vals[key]; + } +}); + window.INVENTREE_SETTINGS = { server_list: { - localhost: { + 'mantine-cqj63coxn': { host: `${window.location.origin}/`, name: 'Current Server' }, ...(IS_DEV_OR_DEMO ? { - demo: { + 'mantine-u56l5jt85': { host: 'https://demo.inventree.org/', name: 'InvenTree Demo' } } : {}) }, - default_server: IS_DEMO ? 'demo' : 'localhost', + default_server: IS_DEMO ? 'mantine-u56l5jt85' : 'mantine-cqj63coxn', show_server_selector: IS_DEV_OR_DEMO, // merge in settings that are already set via django's spa_view or for development - ...((window.INVENTREE_SETTINGS || {}) as any) + ...loaded_vals }; if (window.INVENTREE_SETTINGS.sentry_dsn) { diff --git a/src/frontend/src/states/ApiState.tsx b/src/frontend/src/states/ApiState.tsx index 47fe1bbd5f..d49ff31aa8 100644 --- a/src/frontend/src/states/ApiState.tsx +++ b/src/frontend/src/states/ApiState.tsx @@ -15,9 +15,12 @@ export const useServerApiState = create((set, get) => ({ setServer: (newServer: ServerAPIProps) => set({ server: newServer }), fetchServerApiState: async () => { // Fetch server data - await api.get(apiUrl(ApiPaths.api_server_info)).then((response) => { - set({ server: response.data }); - }); + await api + .get(apiUrl(ApiPaths.api_server_info)) + .then((response) => { + set({ server: response.data }); + }) + .catch(() => {}); } })); diff --git a/src/frontend/src/states/UserState.tsx b/src/frontend/src/states/UserState.tsx index 05ae161660..37f0eb8f09 100644 --- a/src/frontend/src/states/UserState.tsx +++ b/src/frontend/src/states/UserState.tsx @@ -32,7 +32,7 @@ export const useUserState = create((set, get) => ({ // Fetch user data await api .get(apiUrl(ApiPaths.user_me), { - timeout: 5000 + timeout: 2000 }) .then((response) => { const user: UserProps = { diff --git a/src/frontend/src/views/DesktopAppView.tsx b/src/frontend/src/views/DesktopAppView.tsx index d704f4bf2b..c0598c04c7 100644 --- a/src/frontend/src/views/DesktopAppView.tsx +++ b/src/frontend/src/views/DesktopAppView.tsx @@ -27,10 +27,6 @@ export default function DesktopAppView() { ]); // Local state initialization - if (Object.keys(hostList).length === 0) { - console.log('Loading default host list'); - useLocalState.setState({ hostList: defaultHostList }); - } setApiDefaults(); // Server Session @@ -38,6 +34,11 @@ export default function DesktopAppView() { const sessionState = useSessionState.getState(); const [token] = sessionState.token ? [sessionState.token] : [null]; useEffect(() => { + if (Object.keys(hostList).length === 0) { + console.log('Loading default host list', defaultHostList); + useLocalState.setState({ hostList: defaultHostList }); + } + if (token && !fetchedServerSession) { setFetchedServerSession(true); fetchUserState(); diff --git a/src/frontend/tests/ui_plattform.spec.ts b/src/frontend/tests/ui_plattform.spec.ts index 616ad5b460..10c276dbd1 100644 --- a/src/frontend/tests/ui_plattform.spec.ts +++ b/src/frontend/tests/ui_plattform.spec.ts @@ -11,9 +11,4 @@ test('Basic Platform UI test', async ({ page }) => { await page.goto('./platform/'); await expect(page).toHaveTitle('InvenTree Demo Server'); - await expect( - page.getByRole('heading', { - name: 'Welcome to your Dashboard, Ally Access' - }) - ).toBeVisible(); });