# HG changeset patch # User Thomas Junk # Date 1550580902 -3600 # Node ID c98491f9c466b176eada55ae641ae8257ae0590a # Parent ead321473840114f45d4860810f92117bf0747ac router: cleanup auth code diff -r ead321473840 -r c98491f9c466 client/src/router.js --- a/client/src/router.js Tue Feb 19 13:45:39 2019 +0100 +++ b/client/src/router.js Tue Feb 19 13:55:02 2019 +0100 @@ -181,21 +181,6 @@ component: () => import("./components/Main.vue"), meta: { requiresAuth: true - }, - beforeEnter: (to, from, next) => { - const expiresFromPastSession = toMillisFromString( - localStorage.getItem("expires") - ); - if (sessionStillActive(expiresFromPastSession)) { - store.commit("user/setUser", localStorage.getItem("user")); - store.commit("user/setExpires", expiresFromPastSession); - store.commit("user/setRoles", localStorage.getItem("roles")); - store.commit("user/setIsAuthenticate", true); - } else { - store.commit("reset"); - store.commit("user/clearAuth"); - } - next(); } }, { @@ -206,11 +191,20 @@ }); router.beforeEach((to, from, next) => { - const requiresAuth = to.matched.some(record => record.meta.requiresAuth); - const loggedIn = store.state.user.isAuthenticated; const expiresFromPastSession = toMillisFromString( localStorage.getItem("expires") ); + if (sessionStillActive(expiresFromPastSession)) { + store.commit("user/setUser", localStorage.getItem("user")); + store.commit("user/setExpires", expiresFromPastSession); + store.commit("user/setRoles", localStorage.getItem("roles")); + store.commit("user/setIsAuthenticate", true); + } else { + store.commit("reset"); + store.commit("user/clearAuth"); + } + const requiresAuth = to.matched.some(record => record.meta.requiresAuth); + const loggedIn = store.state.user.isAuthenticated; const authRequired = requiresAuth && !(loggedIn || sessionStillActive(expiresFromPastSession)); if (authRequired) {