diff client/src/router.js @ 165:4bf2173748f3

refactor: extracted the string to milisecondconversion Extracted the conversion of session data to string conversion to Method. SRP.
author Thomas Junk <thomas.junk@intevation.de>
date Fri, 06 Jul 2018 11:04:52 +0200
parents 9908260d1e6a
children 9c1dfadb53aa
line wrap: on
line diff
--- a/client/src/router.js	Fri Jul 06 10:51:19 2018 +0200
+++ b/client/src/router.js	Fri Jul 06 11:04:52 2018 +0200
@@ -3,7 +3,7 @@
 import Login from "./views/Login.vue";
 import Main from "./views/Main.vue";
 import store from "./store";
-import { sessionStillActive } from "./lib/session";
+import { sessionStillActive, toMillisFromString } from "./lib/session";
 
 Vue.use(Router);
 
@@ -22,7 +22,9 @@
         requiresAuth: true
       },
       beforeEnter: (to, from, next) => {
-        const expiresFromPastSession = localStorage.getItem("expires");
+        const expiresFromPastSession = toMillisFromString(
+          localStorage.getItem("expires")
+        );
         if (sessionStillActive(expiresFromPastSession)) {
           store.commit("user/set_user", localStorage.getItem("user"));
           store.commit("user/set_expires", expiresFromPastSession);
@@ -44,7 +46,9 @@
 router.beforeEach((to, from, next) => {
   const requiresAuth = to.matched.some(record => record.meta.requiresAuth);
   const loggedIn = store.getters.authenticated;
-  const expiresFromPastSession = localStorage.getItem("expires");
+  const expiresFromPastSession = toMillisFromString(
+    localStorage.getItem("expires")
+  );
   const authRequired =
     requiresAuth && !(loggedIn || sessionStillActive(expiresFromPastSession));
   if (authRequired) {