diff --git a/src/assets/locales/en.json b/src/assets/locales/en.json index 71fb1d78..01d6205e 100644 --- a/src/assets/locales/en.json +++ b/src/assets/locales/en.json @@ -260,7 +260,8 @@ "loadingUserError": { "text": "Failed to load your profile", "textWithReset": "Failed to load your profile from your custom server, want to reset back to the default server?", - "reset": "Reset custom server" + "reset": "Reset custom server", + "logout": "Logout" }, "migration": { "failed": "Failed to migrate your data.", diff --git a/src/index.tsx b/src/index.tsx index 780bd63e..8ef5a560 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -15,6 +15,7 @@ import { useAsync } from "react-use"; import { Button } from "@/components/buttons/Button"; import { Icon, Icons } from "@/components/Icon"; import { Loading } from "@/components/layout/Loading"; +import { useAuth } from "@/hooks/auth/useAuth"; import { useAuthRestore } from "@/hooks/auth/useAuthRestore"; import { useBackendUrl } from "@/hooks/auth/useBackendUrl"; import { ErrorBoundary } from "@/pages/errors/ErrorBoundary"; @@ -57,14 +58,22 @@ function LoadingScreen(props: { type: "user" | "lazy" }) { function ErrorScreen(props: { children: ReactNode; showResetButton?: boolean; + showLogoutButton?: boolean; }) { const { t } = useTranslation(); + const { logout } = useAuth(); const setBackendUrl = useAuthStore((s) => s.setBackendUrl); const resetBackend = useCallback(() => { setBackendUrl(null); // eslint-disable-next-line no-restricted-globals location.reload(); }, [setBackendUrl]); + const logoutFromBackend = useCallback(() => { + logout().then(() => { + // eslint-disable-next-line no-restricted-globals + location.reload(); + }); + }, [logout]); return ( ) : null} + {props.showLogoutButton ? ( +
+ +
+ ) : null}
); } @@ -90,12 +106,17 @@ function AuthWrapper() { const userBackendUrl = useBackendUrl(); const { t } = useTranslation(); + const isCustomUrl = backendUrl !== userBackendUrl; + if (status.loading) return ; if (status.error) return ( - + {t( - backendUrl !== userBackendUrl + isCustomUrl ? "screens.loadingUserError.textWithReset" : "screens.loadingUserError.text" )}