diff client/src/router.js @ 2846:b42d10120cad

client: fixed router redirects when not logged in
author Markus Kottlaender <markus@intevation.de>
date Thu, 28 Mar 2019 14:07:20 +0100
parents d6c90d2c8c8d
children 8b32574bed09
line wrap: on
line diff
--- a/client/src/router.js	Thu Mar 28 12:18:40 2019 +0100
+++ b/client/src/router.js	Thu Mar 28 14:07:20 2019 +0100
@@ -41,7 +41,7 @@
       beforeEnter: (to, from, next) => {
         const isSysadmin = store.getters["user/isSysAdmin"];
         if (!isSysadmin) {
-          next("/");
+          next("/login");
         } else {
           next();
         }
@@ -57,7 +57,7 @@
       beforeEnter: (to, from, next) => {
         const isSysadmin = store.getters["user/isSysAdmin"];
         if (!isSysadmin) {
-          next("/");
+          next("/login");
         } else {
           next();
         }
@@ -74,7 +74,7 @@
       beforeEnter: (to, from, next) => {
         const isWaterwayAdmin = store.getters["user/isWaterwayAdmin"];
         if (!isWaterwayAdmin) {
-          next("/");
+          next("/login");
         } else {
           next();
         }
@@ -90,7 +90,7 @@
       beforeEnter: (to, from, next) => {
         const isWaterwayAdmin = store.getters["user/isWaterwayAdmin"];
         if (!isWaterwayAdmin) {
-          next("/");
+          next("/login");
         } else {
           next();
         }
@@ -106,7 +106,7 @@
       beforeEnter: (to, from, next) => {
         const isWaterwayAdmin = store.getters["user/isWaterwayAdmin"];
         if (!isWaterwayAdmin) {
-          next("/");
+          next("/login");
         } else {
           next();
         }
@@ -122,7 +122,7 @@
       beforeEnter: (to, from, next) => {
         const isWaterwayAdmin = store.getters["user/isWaterwayAdmin"];
         if (!isWaterwayAdmin) {
-          next("/");
+          next("/login");
         } else {
           next();
         }
@@ -138,7 +138,7 @@
       beforeEnter: (to, from, next) => {
         const isWaterwayAdmin = store.getters["user/isWaterwayAdmin"];
         if (!isWaterwayAdmin) {
-          next("/");
+          next("/login");
         } else {
           next();
         }
@@ -184,7 +184,7 @@
       beforeEnter: (to, from, next) => {
         const isWaterwayAdmin = store.getters["user/isWaterwayAdmin"];
         if (!isWaterwayAdmin) {
-          next("/");
+          next("/login");
         } else {
           store.commit("application/showContextBox", true);
           store.commit("application/contextBoxContent", "importoverview");
@@ -203,7 +203,7 @@
       beforeEnter: (to, from, next) => {
         const isSysadmin = store.getters["user/isSysAdmin"];
         if (!isSysadmin) {
-          next("/");
+          next("/login");
         } else {
           store.commit("application/searchQuery", "");
           store.commit("application/showContextBox", true);
@@ -233,24 +233,13 @@
     store.commit("reset");
     store.commit("user/clearAuth");
   }
-  const { tempRoute } = store.state.application;
   const requiresAuth = to.matched.some(record => record.meta.requiresAuth);
-  const loggedIn = store.state.user.isAuthenticated;
-  const authRequired =
-    requiresAuth && !(loggedIn || sessionStillActive(expiresFromPastSession));
-  if (authRequired) {
-    store.commit("application/setTempRoute", to.path);
+  const redirectToLogin = requiresAuth && !store.state.user.isAuthenticated;
+  if (redirectToLogin) {
+    localStorage.setItem("tempRoute", to.path);
     next("/login");
-  } else {
-    if (tempRoute) {
-      const target = tempRoute;
-      store.commit("application/setTempRoute", "");
-      next({
-        path: target,
-        replace: true
-      });
-    } else next();
   }
+  next();
 });
 
 export default router;