From 2411fc86cd22911f02a0d8336e3d8b5200ce03f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Fri, 16 Oct 2020 13:07:31 +0200 Subject: [PATCH] =?UTF-8?q?L=C3=B6schen=20und=20Anzeigen=20von=20Sessions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- quasar.conf.js | 8 +-- src/boot/axios.ts | 6 +- src/boot/login.ts | 22 ++++--- src/plugins/user/pages/Settings.vue | 94 +++++++++++++++++++++++++---- src/plugins/user/store/session.ts | 17 ++++++ src/plugins/user/store/user.ts | 8 +-- 6 files changed, 127 insertions(+), 28 deletions(-) diff --git a/quasar.conf.js b/quasar.conf.js index 91adc15..e6f0708 100644 --- a/quasar.conf.js +++ b/quasar.conf.js @@ -9,7 +9,7 @@ /* eslint-disable @typescript-eslint/no-var-requires */ const { configure } = require('quasar/wrappers'); -module.exports = configure(function (ctx) { +module.exports = configure(function(ctx) { return { // https://quasar.dev/quasar-cli/supporting-ts supportTS: { @@ -64,7 +64,7 @@ module.exports = configure(function (ctx) { // extractCSS: false, // https://quasar.dev/quasar-cli/handling-webpack - extendWebpack (cfg) { + extendWebpack(cfg) { // linting is slow in TS projects, we execute it only for production builds if (ctx.prod) { cfg.module.rules.push({ @@ -103,7 +103,7 @@ module.exports = configure(function (ctx) { // directives: [], // Quasar plugins - plugins: [] + plugins: ['LocalStorage'] }, // animations: 'all', // --- includes all animations @@ -191,7 +191,7 @@ module.exports = configure(function (ctx) { // More info: https://quasar.dev/quasar-cli/developing-electron-apps/node-integration nodeIntegration: true, - extendWebpack (/* cfg */) { + extendWebpack(/* cfg */) { // do something with Electron main process Webpack cfg // chainWebpack also available besides this extendWebpack } diff --git a/src/boot/axios.ts b/src/boot/axios.ts index 4bc0f14..2ade8ff 100644 --- a/src/boot/axios.ts +++ b/src/boot/axios.ts @@ -1,6 +1,6 @@ import axios, { AxiosInstance } from 'axios'; import { boot } from 'quasar/wrappers'; -import { StateInterface } from '../store'; +import { Token, UserStateInterface } from 'src/plugins/user/store/user'; import config from '../config'; declare module 'vue/types/vue' { @@ -15,8 +15,10 @@ export default boot(({ Vue, store }) => { axios.defaults.baseURL = config.baseURL; axios.interceptors.request.use(config => { - const token = (store.state).user.token; + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + const token: Token = (store.state.user).token; if (token) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access config.headers['Authorization'] = 'Token ' + token.token; } return config; diff --git a/src/boot/login.ts b/src/boot/login.ts index ad88e4e..b2c8b0f 100644 --- a/src/boot/login.ts +++ b/src/boot/login.ts @@ -1,19 +1,27 @@ import { boot } from 'quasar/wrappers'; -import { StateInterface } from '../store'; +import { UserStateInterface } from 'src/plugins/user/store/user'; +import { RouteRecord } from 'vue-router'; -export default boot(({ Vue, router, store }) => { +export default boot(({ router, store }) => { router.beforeEach((to, from, next) => { - let user = (store.state).user; + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/ban-ts-comment + // @ts-ignore + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + const user: UserStateInterface = (store.state).user; console.log('login_boot', user); if ( - to.matched.some(record => { + to.matched.some((record: RouteRecord) => { // permissions is set AND has NO matching permission return ( + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access record.meta.permissions !== undefined && !( - record.meta.permissions.filter((value: string) => - user.permissions.includes(value) - ).length > 0 + // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access + ( + record.meta.permissions.filter((value: string) => + user.permissions.includes(value) + ).length > 0 + ) ) ); }) diff --git a/src/plugins/user/pages/Settings.vue b/src/plugins/user/pages/Settings.vue index 4946dcb..0146030 100644 --- a/src/plugins/user/pages/Settings.vue +++ b/src/plugins/user/pages/Settings.vue @@ -4,18 +4,55 @@
Deine Sessions:
- +
@@ -24,19 +61,54 @@ diff --git a/src/plugins/user/store/session.ts b/src/plugins/user/store/session.ts index 8a6112c..8cd8e05 100644 --- a/src/plugins/user/store/session.ts +++ b/src/plugins/user/store/session.ts @@ -40,6 +40,7 @@ const actions: ActionTree = { headers: { Token: rootGetters['user/token'].token } }) .then(response => { + console.log(response.data); commit('setSessions', response.data); }) .catch(error => { @@ -48,6 +49,22 @@ const actions: ActionTree = { .finally(() => { commit('setLoading', false); }); + }, + deleteSession({ commit, dispatch, rootGetters }, token) { + commit('setLoading', true); + axios + .delete(`http://localhost:5000/auth/${token}`, { + headers: { Token: rootGetters['user/token'].token } + }) + .then(() => { + void dispatch('getSessions'); + }) + .catch(error => { + console.exception(); + }) + .finally(() => { + commit('setLoading', false); + }); } }; diff --git a/src/plugins/user/store/user.ts b/src/plugins/user/store/user.ts index 5762565..a721d6b 100644 --- a/src/plugins/user/store/user.ts +++ b/src/plugins/user/store/user.ts @@ -81,10 +81,10 @@ const actions: ActionTree = { commit('setUser', response.data.user); commit('setUserId', response.data.userid); commit('showState'); - //LocalStorage.set('permissions', response.data.permissions); - //LocalStorage.set('token', response.data.token); - //LocalStorage.set('user', response.data.user); - //LocalStorage.set('userid', response.data.userid); + LocalStorage.set('permissions', response.data.permissions); + LocalStorage.set('token', response.data.token); + LocalStorage.set('user', response.data.user); + LocalStorage.set('userid', response.data.userid); void Router.push({ name: 'user' }); })