Skip to content

Commit

Permalink
fix: pass csrf token on doi/manuscript fetch and clean up withCredent…
Browse files Browse the repository at this point in the history
…ials (#1281)

* fix: pass csrf token on doi/manuscript fetch

* remove unnecessary withCredentials

- withCredentials is not part of the fetch api and was just being ignored

* clean up
  • Loading branch information
jaredgalanis authored Jul 8, 2024
1 parent 0964c95 commit 9c34079
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
1 change: 0 additions & 1 deletion app/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export default class ApplicationAdapter extends JSONAPIAdapter {

get headers() {
return {
withCredentials: true,
'X-XSRF-TOKEN': document.cookie.match(/XSRF-TOKEN\=([^;]*)/)['1'],
};
}
Expand Down
1 change: 0 additions & 1 deletion app/components/workflow-files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export default class WorkflowFiles extends Component {
async uploadFile(FileUpload) {
try {
const response = await FileUpload.upload(ENV.fileServicePath, {
withCredentials: true,
headers: {
'X-XSRF-TOKEN': document.cookie.match(/XSRF-TOKEN\=([^;]*)/)['1'],
},
Expand Down
1 change: 0 additions & 1 deletion app/services/doi.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export default class DoiService extends Service {
let rawResponse = yield fetch(url, {
headers: {
Accept: 'application/json; charset=utf-8',
withCredentials: 'include',
'X-XSRF-TOKEN': document.cookie.match(/XSRF-TOKEN\=([^;]*)/)['1'],
},
});
Expand Down
1 change: 1 addition & 0 deletions app/services/metadata-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export default class MetadataSchemaService extends Service {
method: 'GET',
headers: {
'Content-Type': 'application/json; charset=utf-8',
'X-XSRF-TOKEN': document.cookie.match(/XSRF-TOKEN\=([^;]*)/)['1'],
},
};

Expand Down
8 changes: 7 additions & 1 deletion app/services/oa-manuscript-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ export default class OAManuscriptService extends Service {

const url = `${this.lookUpPath}?doi=${doi}`;

return fetch(url, { method: 'GET' })
return fetch(url, {
method: 'GET',
headers: {
Accept: 'application/json; charset=utf-8',
'X-XSRF-TOKEN': document.cookie.match(/XSRF-TOKEN\=([^;]*)/)['1'],
},
})
.then((resp) => {
if (resp.status !== 200) {
console.log(`%cFailed to lookup files for DOI (${doi}). Reason: "${resp.message}"`, 'color: red;');
Expand Down
5 changes: 2 additions & 3 deletions app/services/policies.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export default class PoliciesService extends Service {
const result = await fetch(url, {
method: 'GET',
headers: {
// 'Content-Type': 'application/json'
credentials: 'include',
'X-XSRF-TOKEN': document.cookie.match(/XSRF-TOKEN\=([^;]*)/)['1'],
},
});

Expand Down Expand Up @@ -86,7 +85,7 @@ export default class PoliciesService extends Service {
const response = yield fetch(url, {
method: 'GET',
headers: {
credentials: 'include',
'X-XSRF-TOKEN': document.cookie.match(/XSRF-TOKEN\=([^;]*)/)['1'],
},
});

Expand Down

0 comments on commit 9c34079

Please sign in to comment.