diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 77d9593..6aebeda 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -1,12 +1,10 @@ -import { lazy, Suspense, useEffect } from "react"; +import { lazy, Suspense, useEffect, useRef } from "react"; import { BrowserRouter, Navigate, Route, Routes } from "react-router-dom"; import { ProtectedRoute, PublicRoute } from "./components/RouteGuards"; import SplashScreen from "./components/SplashScreen"; import { ROUTES } from "./config/routes"; import { useAuth } from "./hooks/useAuth"; -let authInitialized = false; - const Activate = lazy(() => import("./pages/Activate")); const Drawer = lazy(() => import("./pages/Drawer")); const Editor = lazy(() => import("./pages/Editor")); @@ -18,11 +16,12 @@ const VerifyEmail = lazy(() => import("./pages/VerifyEmail")); export default function App() { const { initialize, isInitializing } = useAuth(); + const authInitialized = useRef(false); useEffect(() => { - if (authInitialized) return; - authInitialized = true; - initialize(); + if (authInitialized.current) return; + authInitialized.current = true; + initialize().then(); }, [initialize]); if (isInitializing) { diff --git a/frontend/src/utils/crypto.ts b/frontend/src/utils/crypto.ts index 5846afa..942a8aa 100644 --- a/frontend/src/utils/crypto.ts +++ b/frontend/src/utils/crypto.ts @@ -26,7 +26,8 @@ interface SealedEnvelope { // TODO: try refactoring into a pure function for consistency export class CryptoUtils { private dek!: CryptoKey; - private static readonly PBKDF2_ITERATIONS = 600_000; + private static readonly PBKDF2_ITERATIONS = + Number(import.meta.env.VITE_PBKDF2_ITERATIONS) || 600_000; // NOTE: https://www.w3.org/TR/webcrypto/#aes-gcm private static readonly AES_ALGO = { name: "AES-GCM", length: 256 }; private static readonly IV_BYTE_LENGTH = 12; diff --git a/frontend/vitest.config.ts b/frontend/vitest.config.ts index 0aa62f2..64212d1 100644 --- a/frontend/vitest.config.ts +++ b/frontend/vitest.config.ts @@ -9,6 +9,8 @@ export default defineConfig({ env: { VITE_API_URL: "http://piku-server", TZ: "Asia/Kolkata", + // using the actual 600_000 iterations causes timeout in tests + VITE_PBKDF2_ITERATIONS: "1", }, include: ["**/*.test.ts", "**/*.test.tsx"], environment: "jsdom",