From 03b5fd663c29339abd74983d2acbf031adffcc1d Mon Sep 17 00:00:00 2001 From: Dwynr Date: Wed, 28 Aug 2024 17:52:28 +0200 Subject: [PATCH] fix: logout --- src/components/activityHandler.tsx | 15 +---------- src/components/mounts/virtualDrive/index.tsx | 13 +++++++--- src/components/settings/general/index.tsx | 14 +--------- src/lib/setup.ts | 27 +++++++++----------- 4 files changed, 24 insertions(+), 45 deletions(-) diff --git a/src/components/activityHandler.tsx b/src/components/activityHandler.tsx index fc8bb058..694b717d 100644 --- a/src/components/activityHandler.tsx +++ b/src/components/activityHandler.tsx @@ -3,9 +3,7 @@ import useWindowFocus from "@/hooks/useWindowFocus" import worker from "@/lib/worker" import useLocation from "@/hooks/useLocation" import useMountedEffect from "@/hooks/useMountedEffect" -import { useNavigate } from "@tanstack/react-router" import useErrorToast from "@/hooks/useErrorToast" -import { IS_DESKTOP } from "@/constants" import { getSocket } from "@/lib/socket" import { type SocketEvent } from "@filen/sdk" import { logout } from "@/lib/setup" @@ -18,7 +16,6 @@ export const ActivityHandler = memo(() => { const location = useLocation() const [authed] = useIsAuthed() const errorToast = useErrorToast() - const navigate = useNavigate() const isInsidePublicLink = useMemo(() => { return location.includes("/f/") || location.includes("/d/") @@ -55,22 +52,12 @@ export const ActivityHandler = memo(() => { try { await logout() - - if (IS_DESKTOP) { - await window.desktopAPI.restart() - } else { - navigate({ - to: "/login", - replace: true, - resetScroll: true - }) - } } catch (e) { console.error(e) errorToast((e as unknown as Error).message ?? (e as unknown as Error).toString()) } - }, [errorToast, navigate, authed]) + }, [errorToast, authed]) const loggedOutCheck = useCallback(async () => { if (!authed) { diff --git a/src/components/mounts/virtualDrive/index.tsx b/src/components/mounts/virtualDrive/index.tsx index 87663a1d..6336a562 100644 --- a/src/components/mounts/virtualDrive/index.tsx +++ b/src/components/mounts/virtualDrive/index.tsx @@ -269,7 +269,12 @@ export const VirtualDrive = memo(() => { await window.desktopAPI.stopVirtualDrive() } - await Promise.all([isMountedQuery.refetch(), availableDrivesQuery.refetch()]) + await Promise.all([ + isMountedQuery.refetch(), + availableDrivesQuery.refetch(), + cacheSizeQuery.refetch(), + availableCacheSizeQuery.refetch() + ]) setDesktopConfig(prev => ({ ...prev, @@ -302,7 +307,9 @@ export const VirtualDrive = memo(() => { isMountedQuery, availableDrivesQuery, t, - desktopConfig.virtualDriveConfig.mountPoint + desktopConfig.virtualDriveConfig.mountPoint, + cacheSizeQuery, + availableCacheSizeQuery ] ) @@ -455,7 +462,7 @@ export const VirtualDrive = memo(() => { const diskType = await window.desktopAPI.getDiskType(path.paths[0]) - if (!diskType || !diskType.isPhysical) { + if (diskType && !diskType.isPhysical) { errorToast(t("mounts.virtualDrive.errors.invalidCachePath")) return diff --git a/src/components/settings/general/index.tsx b/src/components/settings/general/index.tsx index 8017644a..744ebe99 100644 --- a/src/components/settings/general/index.tsx +++ b/src/components/settings/general/index.tsx @@ -9,7 +9,6 @@ import { useTheme, type Theme } from "@/providers/themeProvider" import useLoadingToast from "@/hooks/useLoadingToast" import useErrorToast from "@/hooks/useErrorToast" import worker from "@/lib/worker" -import { useNavigate } from "@tanstack/react-router" import { IS_DESKTOP } from "@/constants" import { showConfirmDialog } from "@/components/dialogs/confirm" import { Switch } from "@/components/ui/switch" @@ -26,7 +25,6 @@ export const General = memo(() => { const theme = useTheme() const loadingToast = useLoadingToast() const errorToast = useErrorToast() - const navigate = useNavigate() const [chatNotificationsEnabled, setChatNotificationsEnabled] = useLocalStorage("chatNotificationsEnabled", false) const [contactNotificationsEnabled, setContactNotificationsEnabled] = useLocalStorage("contactNotificationsEnabled", false) const [defaultNoteType, setDefaultNoteType] = useLocalStorage("defaultNoteType", "text") @@ -149,16 +147,6 @@ export const General = memo(() => { try { await logout() - - if (IS_DESKTOP) { - await window.desktopAPI.restart() - } else { - navigate({ - to: "/login", - replace: true, - resetScroll: true - }) - } } catch (e) { console.error(e) @@ -167,7 +155,7 @@ export const General = memo(() => { toast.dismiss() } }, - [loadingToast, errorToast, navigate, t] + [loadingToast, errorToast, t] ) const onLanguageChange = useCallback( diff --git a/src/lib/setup.ts b/src/lib/setup.ts index f6688d9e..07fa2be7 100644 --- a/src/lib/setup.ts +++ b/src/lib/setup.ts @@ -90,8 +90,6 @@ export async function setup(config?: FilenSDKConfig, connectToSocket: boolean = if (!isAPIKeyValid) { await logout() - window.location.href = "/login" - return } } @@ -125,12 +123,6 @@ export async function setup(config?: FilenSDKConfig, connectToSocket: boolean = * @returns {Promise} */ export async function logout(): Promise { - if (IS_DESKTOP) { - await Promise.all([window.desktopAPI.stopS3Server(), window.desktopAPI.stopWebDAVServer(), window.desktopAPI.stopVirtualDrive()]) - } - - window.document.title = "Filen" - const cookieConsent = window.localStorage.getItem("cookieConsent") const defaultNoteType = window.localStorage.getItem("defaultNoteType") const videoPlayerVolume = window.localStorage.getItem("videoPlayerVolume") @@ -166,13 +158,18 @@ export async function logout(): Promise { await clearLocalForage() - reinitSDK(DEFAULT_SDK_CONFIG) - - getSDK().init(DEFAULT_SDK_CONFIG) - - await worker.initializeSDK(DEFAULT_SDK_CONFIG) - if (IS_DESKTOP) { - await window.desktopAPI.restartWorker() + await Promise.all([ + window.desktopAPI.stopS3Server(), + window.desktopAPI.stopWebDAVServer(), + window.desktopAPI.stopVirtualDrive(), + window.desktopAPI.stopSync() + ]) + + await new Promise(resolve => setTimeout(resolve, 1000)) + + await window.desktopAPI.restart() + } else { + window.location.reload() } }