Avoid redundant OAuth queries when not signed in
If you aren't signed in, you don't have an auth token. When you don't have an auth token, React was sending the headers "Authorization: Bearer null" This caused 5 Doorkeeper token lookups using WHERE "oauth_access_tokens"."token" = 'null' on the Explore page (the root of the app when not signed in).
This commit is contained in:
parent
31922ea58b
commit
57a88c5904
|
@ -25,16 +25,20 @@ function setCSRFHeader() {
|
|||
|
||||
ready(setCSRFHeader);
|
||||
|
||||
export default getState => axios.create({
|
||||
headers: Object.assign(csrfHeader, getState ? {
|
||||
'Authorization': `Bearer ${getState().getIn(['meta', 'access_token'], '')}`,
|
||||
} : {}),
|
||||
export default getState => {
|
||||
const authToken = getState ? getState().getIn(['meta', 'access_token'], '') : null;
|
||||
|
||||
transformResponse: [function (data) {
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
} catch (Exception) {
|
||||
return data;
|
||||
}
|
||||
}],
|
||||
});
|
||||
return axios.create({
|
||||
headers: Object.assign(csrfHeader, authToken ? {
|
||||
'Authorization': `Bearer ${authToken}}`,
|
||||
} : {}),
|
||||
|
||||
transformResponse: [function (data) {
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
} catch (Exception) {
|
||||
return data;
|
||||
}
|
||||
}],
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue