JavaScript utility function to fetch the CSRF token required to make requests to a Rails server.
yarn add @shopify/csrf-token-fetcher
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 %>
import getCSRFToken from '@shopify/csrf-token-fetcher';
getCSRFToken();
// → 'token_value'