Browse Source

DB being created. Still getting an exception.

kb/add-usage-guide
Matthew Aaron Raymer 2 years ago
parent
commit
3ac8f911ac
  1. 27
      src/db/index.ts
  2. 3
      vue.config.js

27
src/db/index.ts

@ -17,18 +17,21 @@ export type Dexie<T extends unknown = DexieTables> = BaseDexie & T;
export const db = new BaseDexie("kickStarter") as Dexie; export const db = new BaseDexie("kickStarter") as Dexie;
const schema = Object.assign({}, accountsSchema); 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 // if db already made, skip creation
BaseDexie.exists("kickStarter").then(function (exists) { const exists = await BaseDexie.exists("kickStarter");
if (exists == false) { if (exists == false) {
// create password and place password in localStorage // create password and place password in localStorage
const secret = const secret =
localStorage.getItem("secret") || Encryption.createRandomEncryptionKey(); localStorage.getItem("secret") || Encryption.createRandomEncryptionKey();
if (localStorage.getItem("secret") == null) { if (localStorage.getItem("secret") == null) {
localStorage.setItem("secret", secret); localStorage.setItem("secret", secret);
}
encrypted(db, { secretKey: secret });
db.version(1).stores(schema);
} }
});
encrypted(db, { secretKey: secret });
db.version(1).stores(schema);
}

3
vue.config.js

@ -3,5 +3,8 @@ module.exports = defineConfig({
transpileDependencies: true, transpileDependencies: true,
configureWebpack: { configureWebpack: {
devtool: "source-map", devtool: "source-map",
experiments: {
topLevelAwait: true,
}
}, },
}); });

Loading…
Cancel
Save