fix: database wasn't opening
This commit is contained in:
@ -6,6 +6,7 @@ import LoginPage from "./pages/Login";
|
|||||||
import RegisterPage from "./pages/Register";
|
import RegisterPage from "./pages/Register";
|
||||||
import { useDbContext } from "./context/db/db";
|
import { useDbContext } from "./context/db/db";
|
||||||
import { openDB } from "idb";
|
import { openDB } from "idb";
|
||||||
|
import AgreementPage from "./pages/Agreement";
|
||||||
|
|
||||||
const router = createBrowserRouter([
|
const router = createBrowserRouter([
|
||||||
{
|
{
|
||||||
@ -14,7 +15,7 @@ const router = createBrowserRouter([
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/agreement",
|
path: "/agreement",
|
||||||
element: <IndexPage />,
|
element: <AgreementPage />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/login",
|
path: "/login",
|
||||||
@ -31,11 +32,15 @@ const App: FC = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const openConnection = async () => {
|
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")) {
|
const conn = await dbPromise;
|
||||||
conn.createObjectStore("accounts", { keyPath: "accountId" });
|
|
||||||
}
|
|
||||||
|
|
||||||
setDb(conn);
|
setDb(conn);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user