From 8c1bff3a205737cc6f486123a8fc1af054dc48a2 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Fri, 10 May 2019 18:49:51 +0200 Subject: [PATCH] auth evaluation bugfix --- frontend/src/pages/Login.vue | 2 +- frontend/src/pages/MyCaches.vue | 6 +++--- frontend/src/pages/Overview.vue | 9 ++------- frontend/src/pages/Profile.vue | 4 ++-- frontend/src/pages/Register.vue | 4 ++-- frontend/src/router/index.js | 29 +++++++++++++++++------------ 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/frontend/src/pages/Login.vue b/frontend/src/pages/Login.vue index 96418a7..ec2a41d 100644 --- a/frontend/src/pages/Login.vue +++ b/frontend/src/pages/Login.vue @@ -138,7 +138,7 @@ }, evalAuthentication: function () { this.$store.commit('auth/SET_AUTHENTICATED'); - // this.$store.commit('auth/SET_USER'); + this.$store.commit('auth/SET_USER'); }, logout: function () { console.log("logout()"); diff --git a/frontend/src/pages/MyCaches.vue b/frontend/src/pages/MyCaches.vue index d541885..d7e463e 100644 --- a/frontend/src/pages/MyCaches.vue +++ b/frontend/src/pages/MyCaches.vue @@ -11,8 +11,8 @@ indicator-color="cyan-14" switch-indicator > - - + + @@ -115,7 +115,7 @@ }, }, created: function () { - this.$store.commit('auth/SET_AUTHENTICATED'); + // this.$store.commit('auth/SET_AUTHENTICATED'); this.fetchUserCaches(); }, methods: { diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index 5b3c05e..9ea23cf 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -60,7 +60,7 @@ label="Belohnung" size="xs"/> - @@ -118,13 +118,8 @@ return this.$store.getters['auth/GET_ADMINSTATE']; } }, - beforeMount() { - }, - async created() { console.log("created(): " + this.caches); - this.$store.commit('auth/SET_AUTHENTICATED'); - this.$store.commit('auth/SET_USER'); await this.fetchAllCaches(); this.render = await this.fetchMyCaches(); }, @@ -236,7 +231,7 @@ addCache() { this.$router.push({path: `/cache`}) }, - editCache() { + editCache(cacheID) { }, initMap() { console.log("Signalwort: " + this.pois); diff --git a/frontend/src/pages/Profile.vue b/frontend/src/pages/Profile.vue index c711f26..ac4b1c6 100644 --- a/frontend/src/pages/Profile.vue +++ b/frontend/src/pages/Profile.vue @@ -296,8 +296,8 @@ } }, created: function () { - this.$store.commit('auth/SET_AUTHENTICATED'); - this.$store.commit('auth/SET_USER'); + // this.$store.commit('auth/SET_AUTHENTICATED'); + // this.$store.commit('auth/SET_USER'); this.userName = JSON.parse(localStorage.getItem('userToken')).name; this.data[0].userData = this.userName; this.email = JSON.parse(localStorage.getItem('userMail')); diff --git a/frontend/src/pages/Register.vue b/frontend/src/pages/Register.vue index ccd2b3f..2a9d9ae 100644 --- a/frontend/src/pages/Register.vue +++ b/frontend/src/pages/Register.vue @@ -185,8 +185,8 @@ .then((response) => { localStorage.setItem('userToken', JSON.stringify(response.data)); localStorage.setItem('userMail', JSON.stringify(data.email)); - this.$store.commit('auth/SET_AUTHENTICATED'); - this.$store.commit('auth/SET_USER'); + // this.$store.commit('auth/SET_AUTHENTICATED'); + // this.$store.commit('auth/SET_USER'); this.$router.push({path: `/overview`}); }) .catch((error) => { diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js index e56463b..944f157 100644 --- a/frontend/src/router/index.js +++ b/frontend/src/router/index.js @@ -3,18 +3,17 @@ import VueRouter from "vue-router"; import routes from "./routes"; import {axiosInstance} from "../boot/axios"; -Vue.use(VueRouter); -import store from "../store/index"; +Vue.use(VueRouter); /* * If not building with SSR mode, you can * directly export the Router instantiation */ -export default function({ store }/* { store, ssrContext } */) { +export default function ({store}/* { store, ssrContext } */) { const Router = new VueRouter({ - scrollBehavior: () => ({ x: 0, y: 0 }), + scrollBehavior: () => ({x: 0, y: 0}), routes, store, // Leave these as is and change from quasar.conf.js instead! @@ -36,20 +35,23 @@ export default function({ store }/* { store, ssrContext } */) { console.log(loggedIn); const isAdmin = loggedIn ? loggedIn.roles.find(x => x.role === "ADMIN" && x.domain === "geocaching.de") : false; //const isAdmin = true; - if (!isPublic && !loggedIn) { return next({ - path:'/login', + path: '/login', query: {redirect: to.fullPath} // Store the full path to redirect the user to after login }); } + console.log("!isPublic && !loggedIn") if ((loggedIn && onlyWhenLoggedOut) || (loggedIn && onlyAdmin && !isAdmin)) { return next('/') } - if (isPublic) { + console.log("(loggedIn && onlyWhenLoggedOut) || (loggedIn && onlyAdmin && !isAdmin)") + if (isPublic && !loggedIn) { return next() } - if (!isPublic && loggedIn) { + console.log("isPublic") + if (!onlyWhenLoggedOut && loggedIn) { + console.log("fetch data...") axiosInstance.get('/api/getUser', { params: { token: loggedIn.token @@ -57,7 +59,6 @@ export default function({ store }/* { store, ssrContext } */) { }) .then((response) => { console.log("Token valid!"); - store.commit('auth/SET_AUTHENTICATED'); return next(); }) .catch((error) => { @@ -71,16 +72,20 @@ export default function({ store }/* { store, ssrContext } */) { store.commit('dialog/NEW_MESSAGE_DIALOG', { message: "Ihr Token ist nicht mehr gültig. Bitte loggen Sie sich erneut ein.", title: "Bitte erneut anmelden.", - color: "blue", }); + color: "blue", + }); localStorage.removeItem('userToken'); - store.commit('auth/SET_AUTHENTICATED'); return next('/Login'); } else { console.log("unexpected behaviour"); console.log(error); return next(); } - }); + }).finally(() => { + console.log("finally..."); + store.commit('auth/SET_AUTHENTICATED'); + store.commit('auth/SET_USER'); + }); } console.log(`isPublic: ${isPublic} \nonlyWhenLoggedOut: ${onlyWhenLoggedOut} \nonlyAdmin: ${onlyAdmin}`); //return next();