1.0.0 • Published 5 years ago
xsrf-cookie v1.0.0
What is this?
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.
Installation
Using NPM
npm install xsrf-cookie --save
Usage
import { getCookie } from 'xsrf-cookie';
Get XSRF Token from browser cookies
let xsrfToken = getCookie(); // No need to pass the parameter to get xsrf token.Pass XSRF Token in request header
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader('X-XSRF-TOKEN', xsrfToken);
}
})OR
headers: {
'Content-Type': ...,
'X-XSRF-TOKEN': xsrfToken
}Get specific cookie from browser Cookies
let value = getCookie(cookieName); // Pass the parameter with the specific cookieNamePass Specific Cookie in request header
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader('key', value);
}
})OR
headers: {
'Content-Type': ...,
'key': value
}1.0.0
5 years ago