Adding new routing logic ... broken for the moment

This commit is contained in:
Matthew Aaron Raymer
2022-12-07 17:59:37 +08:00
parent ed23317b0f
commit 39f2d73007
3 changed files with 23 additions and 11 deletions

View File

@@ -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<RouteRecordRaw> = [
@@ -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;