Added Pinia account state tracking. Also modified router to go to Start if no account is defined.

This commit is contained in:
Matthew Aaron Raymer
2022-12-02 18:54:47 +08:00
parent 3c388da22d
commit 5c14275a75
4 changed files with 22 additions and 19 deletions

View File

@@ -1,4 +1,5 @@
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import { useAccountStore } from "../store/account";
import HomeView from "../views/HomeView.vue";
const routes: Array<RouteRecordRaw> = [
@@ -109,4 +110,14 @@ const router = createRouter({
routes,
});
router.beforeEach(async (to) => {
// redirect to start page if no account
const publicPages = ["/start"];
const authRequired = !publicPages.includes(to.path);
const authStore = useAccountStore();
if (authRequired && !authStore.account) {
return "/start";
}
});
export default router;