|
| 1 | +import _ from 'lodash'; |
1 | 2 | import * as ClientStartup from './clientStartup'; |
2 | 3 | import handleError from './handleError'; |
3 | 4 | import ComponentRegistry from './ComponentRegistry'; |
@@ -72,23 +73,29 @@ ctx.ReactOnRails = { |
72 | 73 | ClientStartup.reactOnRailsPageLoaded(); |
73 | 74 | }, |
74 | 75 |
|
75 | | - authenticityHeader (options) { |
76 | | - options = options || {}; |
77 | | - return Object.assign(options, { |
78 | | - 'X-CSRF-Token': getAuthenticityToken(), |
79 | | - 'X-Requested-With': 'XMLHttpRequest' |
80 | | - }); |
81 | | - }, |
82 | | - |
83 | 76 | /** |
84 | 77 | * Return CFRS authenticity token inserted by Rails |
85 | 78 | * |
86 | 79 | * @returns CFRS token |
87 | 80 | */ |
88 | 81 |
|
89 | | - getAuthenticityToken () { |
90 | | - let header = document.querySelector(`meta[name="csrf-token"]`); |
91 | | - return header && header.content; |
| 82 | + getAuthenticityToken() { |
| 83 | + const token = _.find(document.querySelectorAll('meta'), ['name', 'csrf-token']); |
| 84 | + return token ? token.content : null; |
| 85 | + }, |
| 86 | + |
| 87 | + /** |
| 88 | + * |
| 89 | + * @param options |
| 90 | + * @returns {*} |
| 91 | + */ |
| 92 | + |
| 93 | + authenticityHeader(options) { |
| 94 | + options = options || {}; |
| 95 | + return Object.assign(options, { |
| 96 | + 'X-CSRF-Token': ReactOnRails.getAuthenticityToken(), |
| 97 | + 'X-Requested-With': 'XMLHttpRequest' |
| 98 | + }); |
92 | 99 | }, |
93 | 100 |
|
94 | 101 | //////////////////////////////////////////////////////////////////////////////// |
|
0 commit comments