diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index ffd2870..0000000 --- a/.tool-versions +++ /dev/null @@ -1 +0,0 @@ -nodejs 16.18.0 diff --git a/src/router/index.ts b/src/router/index.ts index 38611c9..a1ee052 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,5 +1,5 @@ import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router"; -import { useAppStore } from "../store/app"; +import { db } from "@/db"; const routes: Array = [ { @@ -7,10 +7,10 @@ const routes: Array = [ name: "home", component: () => import(/* webpackChunkName: "start" */ "../views/DiscoverView.vue"), - beforeEnter: (to, from, next) => { - const appStore = useAppStore(); - const isAuthenticated = appStore.condition === "registered"; - if (isAuthenticated) { + beforeEnter: async (to, from, next) => { + await db.open(); + const num_accounts = await db.accounts.count(); + if (num_accounts > 0) { next(); } else { next({ name: "start" }); diff --git a/src/store/app.ts b/src/store/app.ts index 0aefd7e..f5e82cb 100644 --- a/src/store/app.ts +++ b/src/store/app.ts @@ -4,10 +4,6 @@ import { defineStore } from "pinia"; export const useAppStore = defineStore({ id: "app", state: () => ({ - _condition: - typeof localStorage["condition"] == "undefined" - ? "uninitialized" - : localStorage["condition"], _lastView: typeof localStorage["lastView"] == "undefined" ? "/start" @@ -18,16 +14,9 @@ export const useAppStore = defineStore({ : localStorage.getItem("projectId"), }), getters: { - condition: (state) => state._condition, projectId: (state): string => state._projectId as string, }, actions: { - reset() { - localStorage.removeItem("condition"); - }, - setCondition(newCondition: string) { - localStorage.setItem("condition", newCondition); - }, async setProjectId(newProjectId: string) { localStorage.setItem("projectId", newProjectId); }, diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index 098f35b..a202dfa 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -168,6 +168,17 @@ + +
+ +

{{ alertTitle }}

+

{{ alertMessage }}

+
@@ -176,7 +187,6 @@ import { Options, Vue } from "vue-class-component"; import { useClipboard } from "@vueuse/core"; import { deriveAddress, generateSeed, newIdentifier } from "../libs/crypto"; import { db } from "../db"; -import { useAppStore } from "@/store/app"; //import { testServerRegisterUser } from "../test"; @Options({ @@ -203,46 +213,68 @@ export default class AccountViewView extends Vue { // 'created' hook runs when the Vue instance is first created async created() { - const appCondition = useAppStore().condition; - if (appCondition == "uninitialized") { - this.mnemonic = generateSeed(); - [this.address, this.privateHex, this.publicHex, this.derivationPath] = - deriveAddress(this.mnemonic); - - const newId = newIdentifier( - this.address, - this.publicHex, - this.privateHex, - this.derivationPath - ); + await db.open(); + const num_accounts = await db.accounts.count(); + if (num_accounts === 0) { try { - await db.open(); - const num_accounts = await db.accounts.count(); - if (num_accounts === 0) { - await db.accounts.add({ - dateCreated: new Date(), - derivationPath: this.derivationPath, - identity: JSON.stringify(newId), - mnemonic: this.mnemonic, - publicKeyHex: newId.keys[0].publicKeyHex, - }); - } - useAppStore().setCondition("registered"); + this.mnemonic = generateSeed(); + [this.address, this.privateHex, this.publicHex, this.derivationPath] = + deriveAddress(this.mnemonic); + + const newId = newIdentifier( + this.address, + this.publicHex, + this.privateHex, + this.derivationPath + ); + await db.accounts.add({ + dateCreated: new Date(), + derivationPath: this.derivationPath, + identity: JSON.stringify(newId), + mnemonic: this.mnemonic, + publicKeyHex: newId.keys[0].publicKeyHex, + }); } catch (err) { + this.alertMessage = + "Clear your cache and start over. Root Cause: " + err; + this.alertTitle = "Error Creating Account"; + this.isAlertVisible = true; console.log(err); } } - await db.open(); - const num_accounts = await db.accounts.count(); - if (num_accounts === 0) { - console.log("Problem! Should have a profile!"); - } else { - const accounts = await db.accounts.toArray(); - const identity = JSON.parse(accounts[0].identity); - this.address = identity.did; - this.publicHex = identity.keys[0].publicKeyHex; - this.derivationPath = identity.keys[0].meta.derivationPath; - } + + const accounts = await db.accounts.toArray(); + const identity = JSON.parse(accounts[0].identity); + this.address = identity.did; + this.publicHex = identity.keys[0].publicKeyHex; + this.derivationPath = identity.keys[0].meta.derivationPath; + } + + alertMessage = ""; + alertTitle = ""; + isAlertVisible = false; + + public onClickClose() { + this.isAlertVisible = false; + this.alertTitle = ""; + this.alertMessage = ""; + } + + public computedAlertClassNames() { + return { + hidden: !this.isAlertVisible, + "dismissable-alert": true, + "bg-slate-100": true, + "p-5": true, + rounded: true, + "drop-shadow-lg": true, + absolute: true, + "top-3": true, + "inset-x-3": true, + "transition-transform": true, + "ease-in": true, + "duration-300": true, + }; } } diff --git a/src/views/ImportAccountView.vue b/src/views/ImportAccountView.vue index b2dfb5c..8738566 100644 --- a/src/views/ImportAccountView.vue +++ b/src/views/ImportAccountView.vue @@ -46,7 +46,6 @@ import { Options, Vue } from "vue-class-component"; import { deriveAddress, newIdentifier } from "../libs/crypto"; import { db } from "@/db"; -import { useAppStore } from "@/store/app"; @Options({ components: {}, @@ -87,7 +86,6 @@ export default class ImportAccountView extends Vue { publicKeyHex: newId.keys[0].publicKeyHex, }); } - useAppStore().setCondition("registered"); this.$router.push({ name: "account" }); } catch (err) { console.log("Error!");