diff --git a/src/router/index.js b/src/router/index.js index 1d8548b..1aa0774 100755 --- a/src/router/index.js +++ b/src/router/index.js @@ -37,14 +37,18 @@ export default route(function (/* { store, ssrContext } */) { ), }); - Router.beforeEach(async (to, from) => { + Router.beforeEach((to, from, next) => { const auth = getAuth(app); const isAuthenticated = auth.currentUser; - const isOnLoginPage = to.name === "Login"; - const isOnRegisterPage = to.name === "Register"; - if (!isAuthenticated && !isOnLoginPage && !isOnRegisterPage) { - return { name: "Login" }; + if (to.matched.some((record) => record.meta.requiresAuth)) { + if (!isAuthenticated) { + next("/login"); + } else { + next(); + } + } else { + next(); } }); diff --git a/src/router/routes.js b/src/router/routes.js index c538890..c2e764a 100755 --- a/src/router/routes.js +++ b/src/router/routes.js @@ -18,12 +18,24 @@ const routes = [ { path: "/painel", component: () => import("layouts/MainLayout.vue"), - children: [{ path: "", component: () => import("pages/Index.vue") }], + children: [ + { + path: "", + component: () => import("pages/Index.vue"), + meta: { requiresAuth: true }, + }, + ], }, { path: "/planos", component: () => import("layouts/MainLayout.vue"), - children: [{ path: "", component: () => import("pages/PlansPage.vue") }], + children: [ + { + path: "", + component: () => import("pages/PlansPage.vue"), + meta: { requiresAuth: true }, + }, + ], }, // Always leave this as last one,