From 39f2d73007aa65b7269d8087ac2db81be41b9f12 Mon Sep 17 00:00:00 2001 From: Matthew Aaron Raymer Date: Wed, 7 Dec 2022 17:59:37 +0800 Subject: [PATCH] Adding new routing logic ... broken for the moment --- src/main.ts | 1 - src/router/index.ts | 20 ++++++++++++++------ src/store/app.ts | 13 +++++++++---- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main.ts b/src/main.ts index 738a07911..01814f63f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,5 @@ import { createPinia } from "pinia"; import { createApp } from "vue"; -import { useAppStore } from "./store/app"; import App from "./App.vue"; import "./registerServiceWorker"; import router from "./router"; diff --git a/src/router/index.ts b/src/router/index.ts index c5d31f357..2421ef1d7 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,5 +1,5 @@ import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router"; -import { useAccountStore } from "../store/account"; +import { useAppStore } from "../store/app"; import HomeView from "../views/HomeView.vue"; const routes: Array = [ @@ -111,13 +111,21 @@ const router = createRouter({ }); router.beforeEach(async (to) => { - // redirect to start page if no account - const publicPages = ["/start", "/account", "/import-account"]; + // redirect to start page if app is uninitialized + const publicPages = ["/start"]; const authRequired = !publicPages.includes(to.path); - const authStore = useAccountStore(); - if (authRequired && !authStore.account) { - return "/start"; + let return_path = "/start"; + if (authRequired) { + switch (useAppStore().condition) { + case "uninitialized": + return_path = "/start"; + break; + case "registering": + return_path = useAppStore().lastView; + break; + } } + return return_path; }); export default router; diff --git a/src/store/app.ts b/src/store/app.ts index 364adae51..c5710c23d 100644 --- a/src/store/app.ts +++ b/src/store/app.ts @@ -2,12 +2,17 @@ import { defineStore } from "pinia"; export const useAppStore = defineStore({ - id: "account", + id: "app", state: () => ({ condition: JSON.parse( - typeof localStorage["app_condition"] == "undefined" + typeof localStorage["condition"] == "undefined" ? "uninitialized" - : localStorage["app_condition"] + : localStorage["condition"] + ), + lastView: JSON.parse( + typeof localStorage["lastView"] == "undefined" + ? "/start" + : localStorage["lastView"] ), }), getters: { @@ -15,7 +20,7 @@ export const useAppStore = defineStore({ }, actions: { reset() { - localStorage.removeItem("app_condition"); + localStorage.removeItem("condition"); }, }, });