sforkowany z mirror/soapbox
Allow API auth with app or user token
rodzic
eef41485c1
commit
238eed4c1a
|
@ -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) {
|
||||
|
|
Ładowanie…
Reference in New Issue