Skip to content

Commit

Permalink
Fix for formTokens to be passed in the request headers for AJAX calls
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevanzuydam committed Nov 20, 2024
1 parent 8f9fd6f commit a91df5f
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/public/js/tina4helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,16 @@ function sendRequest (url, request, method, callback) {
method = 'GET';
}

//Inject the new token
//Inject the new token
if (formToken !== null) {
console.log('Injecting new token');
// check if there is a form token in the url, if so replace it
urlParams = url.searchParams;
urlParams.set('formToken', formToken);
url.search = urlParams.toString();
}

const xhr = new XMLHttpRequest();


xhr.open(method, url, true);

if (formToken !== null) {
//set a form token to the header
xhr.setRequestHeader('Authorization', 'Bearer '+formToken);
}

xhr.onload = function () {
let content = xhr.response;
if (xhr.getResponseHeader('FreshToken') !== '' && xhr.getResponseHeader('FreshToken') !== null) {
Expand Down Expand Up @@ -340,4 +337,4 @@ function getRoute(loadURL, callback) {
sendRequest(loadURL, null, 'GET', function(data) {
callback(handleHtmlData (data, null));
});
}
}

0 comments on commit a91df5f

Please sign in to comment.