From 238eed4c1a8d44c416ac795ec7bdcae56c097e32 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 29 Apr 2020 14:06:26 -0500 Subject: [PATCH] Allow API auth with app or user token --- app/gabsocial/api.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/gabsocial/api.js b/app/gabsocial/api.js index 99c46dcaf..6da5cf464 100644 --- a/app/gabsocial/api.js +++ b/app/gabsocial/api.js @@ -25,13 +25,15 @@ function setCSRFHeader() { ready(setCSRFHeader); -export default getState => { - const user_token = getState().getIn(['auth', 'user', 'access_token']); - const app_token = getState().getIn(['auth', 'app', 'access_token']); - const access_token = user_token || app_token; +const getToken = (getState, authType) => + getState().getIn(['auth', authType, 'access_token']); + +export default (getState, authType = 'user') => { + const accessToken = getToken(getState, authType); + return axios.create({ - headers: Object.assign(csrfHeader, access_token ? { - 'Authorization': `Bearer ${access_token}`, + headers: Object.assign(csrfHeader, accessToken ? { + 'Authorization': `Bearer ${accessToken}`, } : {}), transformResponse: [function(data) {