csrf-xhr

1.0.0 • Public • Published

csrf-xhr

Automatically add Rails CSRF tokens into XMLHttpRequest headers.

How to Use

Load csrf-xhr.js in a <script> anywhere after the <meta name="csrf-token"> that Rails adds to the page.

From now on, any XMLHttpRequest whose destination URL is your local origin (including both relative URLs as well as URLs which explicitly have the same origin as the current page) will have an "X-CSRF-Token" token set to the contents of the <meta name="csrf-token"> that Rails generates in the page's <head>.

jQuery-ujs does this for you; this does it for you even if you aren't using jQuery.

Motivation

This was created to decouple elm-rails from CSRF token management.

Readme

Keywords

Package Sidebar

Install

npm i csrf-xhr

Weekly Downloads

63

Version

1.0.0

License

BSD-3-Clause

Last publish

Collaborators

  • rtfeldman