bigbuffet-rw/app/soapbox/api.js

32 lines
725 B
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
'use strict';
import axios from 'axios';
import LinkHeader from 'http-link-header';
export const getLinks = response => {
const value = response.headers.link;
if (!value) return { refs: [] };
2020-03-27 13:59:38 -07:00
return LinkHeader.parse(value);
};
2020-04-29 12:06:26 -07:00
const getToken = (getState, authType) =>
getState().getIn(['auth', authType, 'access_token']);
export default (getState, authType = 'user') => {
const accessToken = getToken(getState, authType);
2020-04-04 13:28:57 -07:00
return axios.create({
2020-06-09 12:45:48 -07:00
headers: Object.assign(accessToken ? {
2020-04-29 12:06:26 -07:00
'Authorization': `Bearer ${accessToken}`,
2020-04-04 13:28:57 -07:00
} : {}),
transformResponse: [function(data) {
2020-04-04 13:28:57 -07:00
try {
return JSON.parse(data);
} catch(Exception) {
return data;
}
}],
});
};