Browse Source

Fix encrypt-decrypt issue.

experimental_plugin
Matthew Aaron Raymer 2 years ago
parent
commit
4a407b43ae
  1. 17
      src/db/index.ts
  2. 7
      src/views/AccountViewView.vue

17
src/db/index.ts

@ -19,17 +19,14 @@ const schema = Object.assign({}, accountsSchema);
* Needed to enable a special webpack setting to allow *await* below: * 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 * https://stackoverflow.com/questions/72474803/error-the-top-level-await-experiment-is-not-enabled-set-experiments-toplevelaw
*/ */
// if db already made, skip creation
const exists = await BaseDexie.exists("kickStarter"); // create password and place password in localStorage
if (exists == false) { const secret =
// create password and place password in localStorage
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);
}
console.log(secret);
encrypted(db, { secretKey: secret });
db.version(1).stores(schema);
} }
console.log(secret);
encrypted(db, { secretKey: secret });
db.version(1).stores(schema);

7
src/views/AccountViewView.vue

@ -225,7 +225,7 @@ export default class AccountViewView extends Vue {
); );
try { try {
await db.open(); await db.open();
const num_accounts = await db._allTables.accounts.count(); const num_accounts = await db.accounts.count();
if (num_accounts === 0) { if (num_accounts === 0) {
console.log("..."); console.log("...");
await db._allTables.accounts.add({ await db._allTables.accounts.add({
@ -235,7 +235,7 @@ export default class AccountViewView extends Vue {
dateCreated: new Date().getTime(), dateCreated: new Date().getTime(),
}); });
} }
const accounts = await db._allTables.accounts.toArray(); const accounts = await db.accounts.toArray();
console.log(accounts[0]); console.log(accounts[0]);
const identity = JSON.parse(accounts[0].identity); const identity = JSON.parse(accounts[0].identity);
@ -244,8 +244,9 @@ export default class AccountViewView extends Vue {
//appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... created new ID..."})) //appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... created new ID..."}))
//appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... stored new ID..."})) //appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... stored new ID..."}))
} catch { } catch (err) {
console.log("Error!"); console.log("Error!");
console.log(err);
} }
} }
} }

Loading…
Cancel
Save