auth evaluation bugfix

This commit is contained in:
Timo Volkmann 2019-05-10 18:49:51 +02:00
parent f598516ed0
commit 8c1bff3a20
6 changed files with 27 additions and 27 deletions

View File

@ -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()");

View File

@ -11,8 +11,8 @@
indicator-color="cyan-14"
switch-indicator
>
<q-tab name="startedCaches" label="Angefangene Caches" icon="playlist_play"/>
<q-tab name="finishedCaches" label="Beendete Caches" icon="playlist_add_check"/>
<q-tab name="startedCaches" label="Angefangen" icon="playlist_play"/>
<q-tab name="finishedCaches" label="Beendet" icon="playlist_add_check"/>
</q-tabs>
<q-separator color="grey-4"/>
</div>
@ -115,7 +115,7 @@
},
},
created: function () {
this.$store.commit('auth/SET_AUTHENTICATED');
// this.$store.commit('auth/SET_AUTHENTICATED');
this.fetchUserCaches();
},
methods: {

View File

@ -60,7 +60,7 @@
label="Belohnung" size="xs"/>
<q-btn v-if="hasAdminState" @click="confirmDelete(cache.id)" unelevated color="negative" stack
icon="delete" size="xs"/>
<q-btn disable v-if="hasAdminState" @click="editCache(cache.id)" unelevated color="primary" stack
<q-btn v-if="hasAdminState" @click="editCache(cache.id)" unelevated color="primary" stack
icon="edit" size="xs"/>
<q-btn v-if="hasAdminState" @click="generateQrCodes(cache.id)" unelevated color="primary" stack
icon="image" label="QRCodes" 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);

View File

@ -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'));

View File

@ -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) => {

View File

@ -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();