Browse Source

Fix encrypt-decrypt issue.

kb/add-usage-guide
Matthew Aaron Raymer 2 years ago
parent
commit
4a407b43ae
  1. 21
      src/db/index.ts
  2. 7
      src/views/AccountViewView.vue

21
src/db/index.ts

@ -19,17 +19,14 @@ 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
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);
}
console.log(secret);
encrypted(db, { secretKey: secret });
db.version(1).stores(schema);
// create password and place password in localStorage
const secret =
localStorage.getItem("secret") || Encryption.createRandomEncryptionKey();
if (localStorage.getItem("secret") == null) {
localStorage.setItem("secret", secret);
}
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 {
await db.open();
const num_accounts = await db._allTables.accounts.count();
const num_accounts = await db.accounts.count();
if (num_accounts === 0) {
console.log("...");
await db._allTables.accounts.add({
@ -235,7 +235,7 @@ export default class AccountViewView extends Vue {
dateCreated: new Date().getTime(),
});
}
const accounts = await db._allTables.accounts.toArray();
const accounts = await db.accounts.toArray();
console.log(accounts[0]);
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: "... stored new ID..."}))
} catch {
} catch (err) {
console.log("Error!");
console.log(err);
}
}
}

Loading…
Cancel
Save