A function to read X-XSRF-TOKEN from the browser cookie. which can be passed as a payload/headers inside the body or in the request headers respectively.
npm install xsrf-cookie --save
import { getCookie } from 'xsrf-cookie';
let xsrfToken = getCookie(); // No need to pass the parameter to get xsrf token.
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader('X-XSRF-TOKEN', xsrfToken);
}
})
headers: {
'Content-Type': ...,
'X-XSRF-TOKEN': xsrfToken
}
let value = getCookie(cookieName); // Pass the parameter with the specific cookieName
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader('key', value);
}
})
headers: {
'Content-Type': ...,
'key': value
}