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) {