Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Latest commit

 

History

History

csrf-token-fetcher

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

@shopify/csrf-token-fetcher

Caution

@shopify/csrf-token-fetcher is deprecated.

Shopifolk, see Shopify/quilt-internal for information on the latest packages available for use internally.

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'