From 84af5287de7da87fe7c272d26deb5cf24c446a7c Mon Sep 17 00:00:00 2001 From: Matthew Aaron Raymer Date: Thu, 8 Dec 2022 15:37:07 +0800 Subject: [PATCH] Fix to new routing rules --- src/router/index.ts | 27 +++++++++++++++++++-------- src/store/app.ts | 12 +++++------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index 2421ef1..e0b706e 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -112,20 +112,31 @@ const router = createRouter({ router.beforeEach(async (to) => { // redirect to start page if app is uninitialized - const publicPages = ["/start"]; - const authRequired = !publicPages.includes(to.path); - + const publicPages = ["/start", "/account", "/import-account"]; + const isPublic = publicPages.includes(to.path); + const appStore = useAppStore(); + console.log("to:", to.path); let return_path = "/start"; - if (authRequired) { - switch (useAppStore().condition) { + if (isPublic) { + console.log(appStore.condition); + switch (appStore.condition) { case "uninitialized": - return_path = "/start"; + return_path = ""; break; case "registering": - return_path = useAppStore().lastView; + return_path = to.path; break; } + } else { + switch (appStore.condition) { + case "registered": + return_path = to.path; + } + } + if (return_path == "") { + return; + } else { + return return_path; } - return return_path; }); export default router; diff --git a/src/store/app.ts b/src/store/app.ts index c5710c2..900904c 100644 --- a/src/store/app.ts +++ b/src/store/app.ts @@ -4,19 +4,17 @@ import { defineStore } from "pinia"; export const useAppStore = defineStore({ id: "app", state: () => ({ - condition: JSON.parse( + _condition: typeof localStorage["condition"] == "undefined" ? "uninitialized" - : localStorage["condition"] - ), - lastView: JSON.parse( + : localStorage["condition"], + _lastView: typeof localStorage["lastView"] == "undefined" ? "/start" - : localStorage["lastView"] - ), + : localStorage["lastView"], }), getters: { - condition: (state) => state.condition, + condition: (state) => state._condition, }, actions: { reset() {