fix: database wasn't opening

This commit is contained in:
2025-05-24 16:14:53 +02:00
parent c5ee912408
commit 3bcc5f8900

View File

@ -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: <IndexPage />,
element: <AgreementPage />,
},
{
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);
};