Mercurial > gemma
view client/src/router.js @ 172:a422471db08a
Automate running DB-tests with an extra database
run_tests.sh allows to run database tests easily without
affecting other existing databases and on a clean basis.
Because roles are cluster-wide, they cannot be easily droped
and recreated without affecting other databases. Thus,
moved their creation to roles.sql and in passing removed
unnecessary role 'gemma'.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 12 Jul 2018 16:30:01 +0200 |
parents | 4bf2173748f3 |
children | 9c1dfadb53aa |
line wrap: on
line source
import Vue from "vue"; import Router from "vue-router"; import Login from "./views/Login.vue"; import Main from "./views/Main.vue"; import store from "./store"; import { sessionStillActive, toMillisFromString } from "./lib/session"; Vue.use(Router); const router = new Router({ routes: [ { path: "/login", name: "login", component: Login }, { path: "/", name: "mainview", component: Main, meta: { requiresAuth: true }, beforeEnter: (to, from, next) => { const expiresFromPastSession = toMillisFromString( localStorage.getItem("expires") ); if (sessionStillActive(expiresFromPastSession)) { store.commit("user/set_user", localStorage.getItem("user")); store.commit("user/set_expires", expiresFromPastSession); store.commit("user/set_roles", localStorage.getItem("roles")); store.commit("user/set_authenticate", true); } else { store.commit("user/clear_auth"); } next(); } }, { path: "*", component: Login } ] }); router.beforeEach((to, from, next) => { const requiresAuth = to.matched.some(record => record.meta.requiresAuth); const loggedIn = store.getters.authenticated; const expiresFromPastSession = toMillisFromString( localStorage.getItem("expires") ); const authRequired = requiresAuth && !(loggedIn || sessionStillActive(expiresFromPastSession)); if (authRequired) { next("/login"); } else if (!authRequired) { next(); } else { next(); } }); export default router;