@progress/sitefinity-nextjs-sdk
Version:
Provides OOB widgets developed using the Next.js framework, which includes an abstraction layer for Sitefinity communication. Additionally, it offers an expanded API, typings, and tools for further development and integration.
27 lines (26 loc) • 885 B
JavaScript
export class SecurityService {
static setAntiForgeryTokens() {
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest();
xhr.open('GET', '/sitefinity/anticsrf');
xhr.setRequestHeader('X-SF-ANTIFORGERY-REQUEST', 'true');
xhr.responseType = 'json';
xhr.onload = function () {
const response = xhr.response;
if (response != null) {
const token = response.Value;
document.querySelectorAll('input[name = \'sf_antiforgery\']').forEach((i) => i.value = token);
resolve('');
}
else {
resolve('');
}
};
xhr.onerror = function () {
reject();
};
xhr.send();
});
}
;
}