From 3ac8f911ac99b62fbba3b87c376e3814427ce34f Mon Sep 17 00:00:00 2001 From: Matthew Aaron Raymer Date: Thu, 15 Dec 2022 16:45:38 +0800 Subject: [PATCH] DB being created. Still getting an exception. --- src/db/index.ts | 27 +++++++++++++++------------ vue.config.js | 3 +++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/db/index.ts b/src/db/index.ts index b740eb9..fb89a54 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -17,18 +17,21 @@ export type Dexie = BaseDexie & T; export const db = new BaseDexie("kickStarter") as Dexie; const schema = Object.assign({}, accountsSchema); +/** + * Needed to enable a special webpack setting to allow *await* below: + * https://stackoverflow.com/questions/72474803/error-the-top-level-await-experiment-is-not-enabled-set-experiments-toplevelaw + */ // if db already made, skip creation -BaseDexie.exists("kickStarter").then(function (exists) { - if (exists == false) { - // create password and place password in localStorage - const secret = - localStorage.getItem("secret") || Encryption.createRandomEncryptionKey(); +const exists = await BaseDexie.exists("kickStarter"); +if (exists == false) { + // create password and place password in localStorage + const secret = + localStorage.getItem("secret") || Encryption.createRandomEncryptionKey(); - if (localStorage.getItem("secret") == null) { - localStorage.setItem("secret", secret); - } - - encrypted(db, { secretKey: secret }); - db.version(1).stores(schema); + if (localStorage.getItem("secret") == null) { + localStorage.setItem("secret", secret); } -}); + + encrypted(db, { secretKey: secret }); + db.version(1).stores(schema); +} diff --git a/vue.config.js b/vue.config.js index 68babd0..7a47bf4 100644 --- a/vue.config.js +++ b/vue.config.js @@ -3,5 +3,8 @@ module.exports = defineConfig({ transpileDependencies: true, configureWebpack: { devtool: "source-map", + experiments: { + topLevelAwait: true, + } }, });