Skip to content

Commit

Permalink
fix: logout
Browse files Browse the repository at this point in the history
  • Loading branch information
Dwynr committed Aug 28, 2024
1 parent 0929902 commit 03b5fd6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 45 deletions.
15 changes: 1 addition & 14 deletions src/components/activityHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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/")
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 10 additions & 3 deletions src/components/mounts/virtualDrive/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -302,7 +307,9 @@ export const VirtualDrive = memo(() => {
isMountedQuery,
availableDrivesQuery,
t,
desktopConfig.virtualDriveConfig.mountPoint
desktopConfig.virtualDriveConfig.mountPoint,
cacheSizeQuery,
availableCacheSizeQuery
]
)

Expand Down Expand Up @@ -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
Expand Down
14 changes: 1 addition & 13 deletions src/components/settings/general/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -26,7 +25,6 @@ export const General = memo(() => {
const theme = useTheme()
const loadingToast = useLoadingToast()
const errorToast = useErrorToast()
const navigate = useNavigate()
const [chatNotificationsEnabled, setChatNotificationsEnabled] = useLocalStorage<boolean>("chatNotificationsEnabled", false)
const [contactNotificationsEnabled, setContactNotificationsEnabled] = useLocalStorage<boolean>("contactNotificationsEnabled", false)
const [defaultNoteType, setDefaultNoteType] = useLocalStorage<NoteType>("defaultNoteType", "text")
Expand Down Expand Up @@ -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)

Expand All @@ -167,7 +155,7 @@ export const General = memo(() => {
toast.dismiss()
}
},
[loadingToast, errorToast, navigate, t]
[loadingToast, errorToast, t]
)

const onLanguageChange = useCallback(
Expand Down
27 changes: 12 additions & 15 deletions src/lib/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ export async function setup(config?: FilenSDKConfig, connectToSocket: boolean =
if (!isAPIKeyValid) {
await logout()

window.location.href = "/login"

return
}
}
Expand Down Expand Up @@ -125,12 +123,6 @@ export async function setup(config?: FilenSDKConfig, connectToSocket: boolean =
* @returns {Promise<void>}
*/
export async function logout(): Promise<void> {
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")
Expand Down Expand Up @@ -166,13 +158,18 @@ export async function logout(): Promise<void> {

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<void>(resolve => setTimeout(resolve, 1000))

await window.desktopAPI.restart()
} else {
window.location.reload()
}
}

0 comments on commit 03b5fd6

Please sign in to comment.