react-activestorage-provider
Version:
A React component that allows easy file upload using ActiveStorage
17 lines (14 loc) • 398 B
Flow
/**
* Extract the CSRF token from the <%= csrf_meta_tags %>
*
* @providesModule csrfHeader
* @flow
*/
function getToken(): ?string {
const meta = document.querySelector(`meta[name="csrf-token"]`)
return meta && meta.getAttribute('content')
}
export default function csrfHeader(): { 'x-csrf-token'?: string } {
const token = getToken()
return token ? { 'x-csrf-token': token } : {}
}