From 7610ad08b64b43a27bc364cd54c3be63b0bbba9b Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Tue, 24 Aug 2021 21:45:06 +0200 Subject: [PATCH] login expects JWT --- frontend/package.json | 1 + frontend/src/graphql/queries.js | 12 +--------- frontend/src/store/store.js | 23 ++++++++++++------- .../src/views/Layout/DashboardLayout_gdd.vue | 3 +++ frontend/yarn.lock | 12 ++++++++++ 5 files changed, 32 insertions(+), 19 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index 4bc621916..59b34cc9d 100755 --- a/frontend/package.json +++ b/frontend/package.json @@ -72,6 +72,7 @@ "vue-good-table": "^2.21.3", "vue-i18n": "^8.22.4", "vue-jest": "^3.0.7", + "vue-jwt-decode": "^0.1.0", "vue-loading-overlay": "^3.4.2", "vue-moment": "^4.1.0", "vue-qrcode": "^0.3.5", diff --git a/frontend/src/graphql/queries.js b/frontend/src/graphql/queries.js index 3afe807f4..c025584f0 100644 --- a/frontend/src/graphql/queries.js +++ b/frontend/src/graphql/queries.js @@ -2,17 +2,7 @@ import gql from 'graphql-tag' export const login = gql` query($email: String!, $password: String!) { - login(email: $email, password: $password) { - sessionId - user { - email - firstName - lastName - language - username - description - } - } + login(email: $email, password: $password) } ` diff --git a/frontend/src/store/store.js b/frontend/src/store/store.js index 03be5e75c..de3589521 100644 --- a/frontend/src/store/store.js +++ b/frontend/src/store/store.js @@ -1,6 +1,8 @@ import Vue from 'vue' import Vuex from 'vuex' import createPersistedState from 'vuex-persistedstate' +import VueJwtDecode from 'vue-jwt-decode' + Vue.use(Vuex) export const mutations = { @@ -25,17 +27,22 @@ export const mutations = { description: (state, description) => { state.description = description }, + token: (state, token) => { + state.token = token + }, } export const actions = { - login: ({ dispatch, commit }, data) => { - commit('sessionId', data.sessionId) - commit('email', data.user.email) - commit('language', data.user.language) - commit('username', data.user.username) - commit('firstName', data.user.firstName) - commit('lastName', data.user.lastName) - commit('description', data.user.description) + login: ({ dispatch, commit }, token) => { + const decoded = VueJwtDecode.decode(token) + commit('sessionId', decoded.sessionId) + commit('email', decoded.email) + commit('language', decoded.language) + commit('username', decoded.username) + commit('firstName', decoded.firstName) + commit('lastName', decoded.lastName) + commit('description', decoded.description) + commit('token', token) }, logout: ({ commit, state }) => { commit('sessionId', null) diff --git a/frontend/src/views/Layout/DashboardLayout_gdd.vue b/frontend/src/views/Layout/DashboardLayout_gdd.vue index 4081f4ceb..d12f3447c 100755 --- a/frontend/src/views/Layout/DashboardLayout_gdd.vue +++ b/frontend/src/views/Layout/DashboardLayout_gdd.vue @@ -107,6 +107,7 @@ export default { }, async updateTransactions(pagination) { this.pending = true + console.log('Session ID', this.$store.state.sessionId) this.$apollo .query({ query: transactionsQuery, @@ -118,9 +119,11 @@ export default { fetchPolicy: 'network-only', }) .then((result) => { + console.log(result) const { data: { transactionList }, } = result + console.log(transactionList) this.GdtBalance = Number(transactionList.gdtSum) this.transactions = transactionList.transactions this.balance = Number(transactionList.decay) diff --git a/frontend/yarn.lock b/frontend/yarn.lock index eff78ada1..c910ea9de 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -13576,6 +13576,13 @@ vue-jest@^3.0.5, vue-jest@^3.0.7: tsconfig "^7.0.0" vue-template-es2015-compiler "^1.6.0" +vue-jwt-decode@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/vue-jwt-decode/-/vue-jwt-decode-0.1.0.tgz#f9caf7b9030d5459cc567b1c3117d9d1f291458f" + integrity sha512-4iP0NzYHkAF7G13tYPc/nudk4oNpB8GCVZupc7lekxXok1XKEgefNaGTpDT14g7RKe5H9GaMphPduDj4UVfZwQ== + dependencies: + vue "^2.3.3" + vue-loader@^15.7.0: version "15.9.6" resolved "https://registry.yarnpkg.com/vue-loader/-/vue-loader-15.9.6.tgz#f4bb9ae20c3a8370af3ecf09b8126d38ffdb6b8b" @@ -13655,6 +13662,11 @@ vue@^2.2.6, vue@^2.5.17, vue@^2.6.11: resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.12.tgz#f5ebd4fa6bd2869403e29a896aed4904456c9123" integrity sha512-uhmLFETqPPNyuLLbsKz6ioJ4q7AZHzD8ZVFNATNyICSZouqP2Sz0rotWQC8UNBF6VGSCs5abnKJoStA6JbCbfg== +vue@^2.3.3: + version "2.6.14" + resolved "https://registry.yarnpkg.com/vue/-/vue-2.6.14.tgz#e51aa5250250d569a3fbad3a8a5a687d6036e235" + integrity sha512-x2284lgYvjOMj3Za7kqzRcUSxBboHqtgRE2zlos1qWaOye5yUmHn42LB1250NJBLRwEcdrB0JRwyPTEPhfQjiQ== + vuex-persistedstate@^4.0.0-beta.3: version "4.0.0-beta.3" resolved "https://registry.yarnpkg.com/vuex-persistedstate/-/vuex-persistedstate-4.0.0-beta.3.tgz#89dd712de72d28e85cc95467d066002c1405f277"