@shopify/csrf-token-fetcher
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

@shopify/csrf-token-fetcher

Build Status Build Status License: MIT npm version npm bundle size (minified + gzip)

JavaScript utility function to fetch the CSRF token required to make requests to a Rails server.

Installation

$ yarn add @shopify/csrf-token-fetcher

API Reference

function getCSRFToken(scope = document)

Retrieve the CSRF token from the meta tag rendered by a Rails server. This token is required in the X-CSRF-Token header for requests to the Rails server.

In the html.erb file:

<%= csrf_meta_tags %>

Example Usage

import getCSRFToken from '@shopify/csrf-token-fetcher';

getCSRFToken();
// → 'token_value'

Readme

Keywords

none

Package Sidebar

Install

npm i @shopify/csrf-token-fetcher

Weekly Downloads

7,371

Version

2.0.1

License

MIT

Unpacked Size

4.52 kB

Total Files

10

Last publish

Collaborators

  • jaimie.rockburn
  • blittle
  • shopify-admin
  • maryharte
  • crisfmb
  • pmoloney89
  • netlohan
  • st999999
  • justin-irl
  • megswim
  • wcandillon
  • nathanpjf
  • shopify-dep
  • goodforonefare
  • lemonmade
  • vsumner
  • wizardlyhel
  • antoine.grant
  • tsov
  • andyw8-shopify
  • henrytao
  • hannachen
  • vividviolet
  • bpscott