From e080a1a7593e83a49d623ffdd452fd0e1c617889 Mon Sep 17 00:00:00 2001 From: Derick Montague Date: Wed, 4 Dec 2019 16:30:08 -0600 Subject: Add login and logout functionality - Add AuthenticationStore - Add ability to login and logout - Add route navigation guard - Add login styles - Add temporary authentication for api call - Add Login directory - Add index.js In order to login a .env.development.local file that contains BASE_URL="https:// or " Signed-off-by: Derick Montague Change-Id: I88b93e287e66f4bae82a1ec2934cdef12d78264e --- src/router/index.js | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'src/router') diff --git a/src/router/index.js b/src/router/index.js index 11d1a475..698aa700 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,28 +1,35 @@ import Vue from "vue"; import VueRouter from "vue-router"; +import store from "../store/index"; +import AppLayout from "../layouts/AppLayout.vue"; Vue.use(VueRouter); const routes = [ { path: "/", - name: "overview", - component: () => import("@/views/Overview") + name: "", + meta: { + requiresAuth: true + }, + component: AppLayout, + children: [ + { + path: "", + component: () => import("@/views/Overview") + }, + { + path: "/access-control/local-user-management", + name: "local-users", + component: () => import("@/views/AccessControl/LocalUserManagement") + } + ] }, { - path: "/access-control/local-user-management", - name: "local-users", - component: () => import("@/views/AccessControl/LocalUserManagement") + path: "/login", + name: "login", + component: () => import("@/views/Login") } - // { - // path: "/about", - // name: "about", - // // route level code-splitting - // // this generates a separate chunk (about.[hash].js) for this route - // // which is lazy-loaded when the route is visited. - // component: () => - // import(/* webpackChunkName: "about" */ "../views/About.vue") - // } ]; const router = new VueRouter({ @@ -32,4 +39,16 @@ const router = new VueRouter({ linkExactActiveClass: "nav__link--current" }); +router.beforeEach((to, from, next) => { + if (to.matched.some(record => record.meta.requiresAuth)) { + if (store.getters["authentication/isLoggedIn"]) { + next(); + return; + } + next("/login"); + } else { + next(); + } +}); + export default router; -- cgit v1.2.3