Skip to content

This package allows us to read xsrf token or custom cookie from broswers cookie on client side ReactJs/AngularJs/Javascript.

License

Notifications You must be signed in to change notification settings

pravin-yadav/xsrf-cookie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 cookieName

Pass Specific Cookie in request header
$.ajaxSetup({
    beforeSend: function(xhr) {
      xhr.setRequestHeader('key', value);
    }
})

OR

 headers: {
  'Content-Type': ...,
  'key': value
}

About

This package allows us to read xsrf token or custom cookie from broswers cookie on client side ReactJs/AngularJs/Javascript.

Resources

License

Stars

Watchers

Forks

Packages

No packages published