From b479e3ad48a556904be4b93b8600d9b141569f18 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Mon, 9 Nov 2020 03:40:51 +0100 Subject: [PATCH] Some work on login process * Forward already autheticated users * If not auteticated forward back to login * Clear current user if no valid session --- package-lock.json | 19 +++++--- package.json | 12 ++--- src/boot/axios.ts | 7 ++- src/boot/login.ts | 8 +++- src/layouts/MainLayout.vue | 12 ++--- src/pages/Login.vue | 17 ++++++- src/plugins/user/store/session.ts | 74 ++++++++++++++++++------------- tsconfig.json | 3 +- 8 files changed, 97 insertions(+), 55 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4ffac81..b477686 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1719,6 +1719,12 @@ "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.5.tgz", "integrity": "sha512-hSAifV3k+i6lEoCJ2k6R2Z/rp/H3+8sdmcn5NrS3/3kE7+RyZXm9aqvxWqjEXHAd8b0pShatpcdMTvEdvAJltQ==", "dev": true + }, + "vue-router": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.2.0.tgz", + "integrity": "sha512-khkrcUIzMcI1rDcNtqkvLwfRFzB97GmJEsPAQdj7t/VvpGhmXLOkUfhc+Ah8CvpSXGXwuWuQO+x8Sy/xDhXZIA==", + "dev": true } } }, @@ -4262,9 +4268,9 @@ } }, "core-js": { - "version": "3.6.5", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.6.5.tgz", - "integrity": "sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA==" + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.7.0.tgz", + "integrity": "sha512-NwS7fI5M5B85EwpWuIwJN4i/fbisQUwLwiSNUWeXlkAZ0sbBjLEvLvFLf1uzAUV66PcEPt4xCGCmOZSxVf3xzA==" }, "core-js-compat": { "version": "3.6.5", @@ -13650,10 +13656,9 @@ } }, "vue-router": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.2.0.tgz", - "integrity": "sha512-khkrcUIzMcI1rDcNtqkvLwfRFzB97GmJEsPAQdj7t/VvpGhmXLOkUfhc+Ah8CvpSXGXwuWuQO+x8Sy/xDhXZIA==", - "dev": true + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.3.2.tgz", + "integrity": "sha512-5sEbcfb7MW8mY8lbUVbF4kgcipGXsagkM/X+pb6n0MhjP+RorWIUTPAPSqgPaiPOxVCXgAItBl8Vwz8vq78faA==" }, "vue-server-renderer": { "version": "2.6.12", diff --git a/package.json b/package.json index fb37c23..caa7fca 100644 --- a/package.json +++ b/package.json @@ -13,8 +13,9 @@ "@quasar/extras": "^1.9.10", "@vue/composition-api": "^0.6.4", "axios": "^0.18.1", - "core-js": "^3.6.5", - "quasar": "^1.14.3" + "core-js": "^3.7.0", + "quasar": "^1.14.3", + "vue-router": "3.3.2" }, "devDependencies": { "@quasar/app": "^2.1.6", @@ -34,15 +35,14 @@ "last 10 Chrome versions", "last 10 Firefox versions", "last 4 Edge versions", - "last 7 Safari versions", + "last 6 Safari versions", "last 8 Android versions", "last 8 ChromeAndroid versions", "last 8 FirefoxAndroid versions", - "last 10 iOS versions", - "last 5 Opera versions" + "last 10 iOS versions" ], "engines": { - "node": ">= 10.18.1", + "node": ">= 11.0.0", "npm": ">= 6.13.4", "yarn": ">= 1.21.1" } diff --git a/src/boot/axios.ts b/src/boot/axios.ts index 0ee01ac..da8b148 100644 --- a/src/boot/axios.ts +++ b/src/boot/axios.ts @@ -36,10 +36,13 @@ export default boot>(({ Vue, store }) => { error => { if (error) { const e = error; - if (e.code === 'ECONNABORTED' || e.response && e.response.status === 502) { + if ( + e.code === 'ECONNABORTED' || + (e.response && e.response.status === 502) + ) { store.commit('session/setOffline', true); } else if (e.response && e.response.status == 401) { - return store.dispatch('session/clearup'); + return store.dispatch('session/clearCurrent'); } } return Promise.reject(error); diff --git a/src/boot/login.ts b/src/boot/login.ts index 553db5b..38757d1 100644 --- a/src/boot/login.ts +++ b/src/boot/login.ts @@ -35,7 +35,13 @@ export default boot>(({ router, store }) => { next({ name: 'login', query: { redirect: to.fullPath } }); } } else { - next(); + if (store.state.user.currentUser && !to.params['logout']) { + // Called login while already logged in + void next({ name: 'user-main' }); + } else { + // Not logged in or from logout + next(); + } } }); }); diff --git a/src/layouts/MainLayout.vue b/src/layouts/MainLayout.vue index 6a05142..0f0e5b0 100644 --- a/src/layouts/MainLayout.vue +++ b/src/layouts/MainLayout.vue @@ -105,7 +105,7 @@ import EssentialLink from 'components/navigation/EssentialLink.vue'; import ShortCutLink from 'components/navigation/ShortCutLink.vue'; import BackendOffline from 'components/loading/BackendOffline.vue'; -import { Screen } from 'quasar'; +import { Screen, Loading } from 'quasar'; import { defineComponent, ref, computed } from '@vue/composition-api'; import { Store } from 'vuex'; import { StateInterface } from 'src/store'; @@ -180,11 +180,11 @@ export default defineComponent({ }); function logout() { - const store = >ctx.root.$store; - store - .dispatch('session/logout', store.state.session.currentSession?.token) - .catch(error => { - console.warn(error); + Loading.show({ message: 'Session wird abgemeldet' }); + (>ctx.root.$store) + .dispatch('session/logout') + .finally(() => { + Loading.hide(); }); } diff --git a/src/pages/Login.vue b/src/pages/Login.vue index 32a7097..c6e7566 100644 --- a/src/pages/Login.vue +++ b/src/pages/Login.vue @@ -35,10 +35,14 @@