diff --git a/apps/web/src/bootstrap.tsx b/apps/web/src/bootstrap.tsx index d3dedfef3..cb2a758b2 100644 --- a/apps/web/src/bootstrap.tsx +++ b/apps/web/src/bootstrap.tsx @@ -116,9 +116,12 @@ const sessionExpiryExceptions: Routes[] = [ ]; function getRoute(): RouteWithPath | RouteWithPath { - const path = getCurrentPath() as Routes; + let path = getCurrentPath() as Routes; // logger.info(`Getting route for path: ${path}`); + const isAccountRecovery = isAccountRecoveryRoute(path); + if (isAccountRecovery) path = "/account/recovery"; + const signup = redirectToRegistration(path); const sessionExpired = isSessionExpired(path); const fallback = fallbackRoute(); @@ -135,6 +138,10 @@ function getRoute(): RouteWithPath | RouteWithPath { return signup || sessionExpired || route || fallback; } +function isAccountRecoveryRoute(path: Routes): boolean { + return path.startsWith("/account/recovery"); +} + function fallbackRoute(): RouteWithPath { return { route: routes.default, path: "default" }; } @@ -187,7 +194,13 @@ export async function init() { initializeLogger() ]); - return { Component, path, props: route.props }; + const persistence = + (path !== "/sessionexpired" && isAccountRecoveryRoute(path)) || + Config.get("sessionExpired", false) + ? ("db" as const) + : ("memory" as const); + + return { Component, path, props: route.props, persistence }; } function shouldSkipInitiation() { diff --git a/apps/web/src/root.tsx b/apps/web/src/root.tsx index 58be326c7..050d9aa4f 100644 --- a/apps/web/src/root.tsx +++ b/apps/web/src/root.tsx @@ -27,7 +27,6 @@ import { } from "./components/error-boundary"; import { desktop } from "./common/desktop-bridge"; import { useKeyStore } from "./interfaces/key-store"; -import Config from "./utils/config"; import { usePromise } from "@notesnook/common"; import { AuthProps } from "./views/auth"; import { loadDatabase } from "./hooks/use-database"; @@ -52,13 +51,8 @@ export async function startApp(children?: React.ReactNode) { : await import("./components/title-bar").then((m) => m.TitleBar); try { - const { Component, props, path } = await init(); + const { Component, props, path, persistence } = await init(); - const persistence = - (path !== "/sessionexpired" && path !== "/account/recovery") || - Config.get("sessionExpired", false) - ? "db" - : "memory"; await useKeyStore.getState().init({ persistence }); root.render( diff --git a/apps/web/src/views/recovery.tsx b/apps/web/src/views/recovery.tsx index c602cc806..96ce23f03 100644 --- a/apps/web/src/views/recovery.tsx +++ b/apps/web/src/views/recovery.tsx @@ -123,6 +123,7 @@ function useAuthenticateUser({ const user = await db.user.fetchUser(); setUser(user); } catch (e) { + console.error(e); showToast("error", strings.biometricsAuthFailed()); openURL("/"); } finally {