Mercurial > gemma
view client/src/router.js @ 264:78f96f168b59
Online Map: Fix projection and add TileWMS sample
author | Frank Koormann <frank@intevation.de> |
---|---|
date | Fri, 27 Jul 2018 16:29:39 +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;