Skip to content

Commit

Permalink
hotfix before send request
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineRelief committed Aug 31, 2023
1 parent 646fe03 commit 0da1c71
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions libs/safe/src/lib/survey/global-properties/others.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ export const init = (Survey: any, environment: any): void => {
required: true,
});
// Pass token before the request to fetch choices by URL if it's targeting SAFE API
// Survey.ChoicesRestful.onBeforeSendRequest = (
// sender: ChoicesRestful,
// options: { request: { headers: Headers } }
// ) => {
// if (sender.url.includes(environment.apiUrl)) {
// const token = localStorage.getItem('idtoken');
// options.request.headers.append('Authorization', `Bearer ${token}`);
// }
// };
Survey.ChoicesRestful.onBeforeSendRequest = (
sender: ChoicesRestful,
options: { request: { headers: Headers } }
options: { request: XMLHttpRequest }
) => {
if (sender.url.includes(environment.apiUrl)) {
const token = localStorage.getItem('idtoken');
options.request.headers.append('Authorization', `Bearer ${token}`);
options.request.setRequestHeader('Authorization', `Bearer ${token}`);
}
};

Expand Down

0 comments on commit 0da1c71

Please sign in to comment.