forked from jsnbuchanan/crowd-funder-for-time-pwa
Added Pinia account state tracking. Also modified router to go to Start if no account is defined.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user