From 2eb4651aa4564e9cb023529b3344993568e2a3ec Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Thu, 29 Jul 2021 16:51:48 +0200 Subject: [PATCH] provide the auth token with limited requests --- src/store/modules/auth/getters.js | 3 +++ src/store/modules/coaches/actions.js | 8 +++++++- src/store/modules/requests/actions.js | 12 ++++++++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/store/modules/auth/getters.js b/src/store/modules/auth/getters.js index aee2b9d..0e08cac 100644 --- a/src/store/modules/auth/getters.js +++ b/src/store/modules/auth/getters.js @@ -1,5 +1,8 @@ export default { userId(state) { return state.userId; + }, + token(state) { + return state.token; } }; diff --git a/src/store/modules/coaches/actions.js b/src/store/modules/coaches/actions.js index 0a35ec5..089e44e 100644 --- a/src/store/modules/coaches/actions.js +++ b/src/store/modules/coaches/actions.js @@ -12,8 +12,14 @@ export default { areas: data.areas }; + const token = context.rootGetters.token; + const axiosConfig = { + params: { auth: token } + }; + try { - await getAPI.put(`coaches/${userId}.json`, coachData); + console.log(axiosConfig); + await getAPI.put(`coaches/${userId}.json`, coachData, axiosConfig); context.commit('registerCoach', { ...coachData, id: userId diff --git a/src/store/modules/requests/actions.js b/src/store/modules/requests/actions.js index ec8a2b0..43ad0dc 100644 --- a/src/store/modules/requests/actions.js +++ b/src/store/modules/requests/actions.js @@ -21,9 +21,17 @@ export default { } }, async fetchRequests(context) { + const coachId = context.rootGetters.userId; + const token = context.rootGetters.token; + const axiosConfig = { + params: { auth: token } + }; + try { - const coachId = context.rootGetters.userId; - const response = await getAPI.get(`requests/${coachId}.json`); + const response = await getAPI.get( + `requests/${coachId}.json`, + axiosConfig + ); const responseData = await response.data; const requests = [];