From 3bcc5f8900881fe338878ea014642163e99ec936 Mon Sep 17 00:00:00 2001 From: LandaMm Date: Sat, 24 May 2025 16:14:53 +0200 Subject: [PATCH] fix: database wasn't opening --- web/src/App.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/web/src/App.tsx b/web/src/App.tsx index d494bfd..e7edba7 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -6,6 +6,7 @@ import LoginPage from "./pages/Login"; import RegisterPage from "./pages/Register"; import { useDbContext } from "./context/db/db"; import { openDB } from "idb"; +import AgreementPage from "./pages/Agreement"; const router = createBrowserRouter([ { @@ -14,7 +15,7 @@ const router = createBrowserRouter([ }, { path: "/agreement", - element: , + element: , }, { path: "/login", @@ -31,11 +32,15 @@ const App: FC = () => { useEffect(() => { const openConnection = async () => { - const conn = await openDB("guard-local", 3); + const dbPromise = openDB("guard-local", 3, { + upgrade: (db) => { + if (!db.objectStoreNames.contains("accounts")) { + db.createObjectStore("accounts", { keyPath: "accountId" }); + } + }, + }); - if (!conn.objectStoreNames.contains("accounts")) { - conn.createObjectStore("accounts", { keyPath: "accountId" }); - } + const conn = await dbPromise; setDb(conn); };