diff --git a/apps/app-frontend/src/App.vue b/apps/app-frontend/src/App.vue index d8148524d..a7488f53b 100644 --- a/apps/app-frontend/src/App.vue +++ b/apps/app-frontend/src/App.vue @@ -60,6 +60,7 @@ import { useQuery } from '@tanstack/vue-query' import { getVersion } from '@tauri-apps/api/app' import { invoke } from '@tauri-apps/api/core' import { getCurrentWindow } from '@tauri-apps/api/window' +import { fetch as tauriFetch } from '@tauri-apps/plugin-http' import { openUrl } from '@tauri-apps/plugin-opener' import { type } from '@tauri-apps/plugin-os' import { saveWindowState, StateFlags } from '@tauri-apps/plugin-window-state' @@ -446,7 +447,7 @@ router.afterEach((to, from, failure) => { failed: failure, }) setTimeout(() => { - if (!suspensePending) { + if (!suspensePending && stateInitialized.value) { loading.stopLoading() } }, 100) @@ -504,9 +505,27 @@ setupAuthProvider(credentials, async (_redirectPath) => { await signIn() }) +async function validateSession(sessionToken) { + try { + const response = await tauriFetch(`${config.labrinthBaseUrl}/v2/user`, { + method: 'GET', + headers: { Authorization: sessionToken }, + }) + if (response.status === 401) return false + return true + } catch { + return true + } +} + async function fetchCredentials() { const creds = await getCreds().catch(handleError) if (creds && creds.user_id) { + if (creds.session && !(await validateSession(creds.session))) { + await logout().catch(handleError) + credentials.value = null + return + } creds.user = await get_user(creds.user_id, 'bypass').catch(handleError) } credentials.value = creds ?? null diff --git a/apps/app-frontend/src/components/ui/SplashScreen.vue b/apps/app-frontend/src/components/ui/SplashScreen.vue index d15c6fb4d..790589bf0 100644 --- a/apps/app-frontend/src/components/ui/SplashScreen.vue +++ b/apps/app-frontend/src/components/ui/SplashScreen.vue @@ -100,24 +100,38 @@ const loadingProgress = ref(0) const hidden = ref(false) const message = ref() +// const MIN_DISPLAY_MS = 1000 +// const mountedAt = Date.now() + const loading = useLoading() -watch(loading, (newValue) => { - if (!newValue.barEnabled) { - if (loading.loading) { - loadingProgress.value = 0 - fakeLoadingIncrease() - } else { - loadingProgress.value = 100 - doneLoading.value = true +watch( + loading, + (newValue) => { + if (!newValue.barEnabled) { + if (loading.loading) { + loadingProgress.value = 0 + fakeLoadingIncrease() + } else { + // const elapsed = Date.now() - mountedAt + // const delay = Math.max(0, MIN_DISPLAY_MS - elapsed) - setTimeout(() => { - hidden.value = true - loading.setEnabled(true) - }, 50) + // setTimeout(() => { + // if (loading.loading) return + + loadingProgress.value = 100 + doneLoading.value = true + + setTimeout(() => { + hidden.value = true + loading.setEnabled(true) + }, 50) + // }, delay) + } } - } -}) + }, + { immediate: true }, +) function fakeLoadingIncrease() { if (loadingProgress.value < 95) { diff --git a/apps/app-frontend/src/pages/hosting/manage/Index.vue b/apps/app-frontend/src/pages/hosting/manage/Index.vue index c9837956e..fe4b1702f 100644 --- a/apps/app-frontend/src/pages/hosting/manage/Index.vue +++ b/apps/app-frontend/src/pages/hosting/manage/Index.vue @@ -1,10 +1,12 @@