mirror of https://github.com/Siphonay/mastodon
Use vanilla JS to get Rails CSRF values (#29403)
This commit is contained in:
parent
d4ed7e466c
commit
00d94f3ffa
|
@ -1,5 +1,3 @@
|
|||
import Rails from '@rails/ujs';
|
||||
|
||||
export const logOut = () => {
|
||||
const form = document.createElement('form');
|
||||
|
||||
|
@ -9,13 +7,18 @@ export const logOut = () => {
|
|||
methodInput.setAttribute('type', 'hidden');
|
||||
form.appendChild(methodInput);
|
||||
|
||||
const csrfToken = Rails.csrfToken();
|
||||
const csrfParam = Rails.csrfParam();
|
||||
const csrfToken = document.querySelector<HTMLMetaElement>(
|
||||
'meta[name=csrf-token]',
|
||||
);
|
||||
|
||||
const csrfParam = document.querySelector<HTMLMetaElement>(
|
||||
'meta[name=csrf-param]',
|
||||
);
|
||||
|
||||
if (csrfParam && csrfToken) {
|
||||
const csrfInput = document.createElement('input');
|
||||
csrfInput.setAttribute('name', csrfParam);
|
||||
csrfInput.setAttribute('value', csrfToken);
|
||||
csrfInput.setAttribute('name', csrfParam.content);
|
||||
csrfInput.setAttribute('value', csrfToken.content);
|
||||
csrfInput.setAttribute('type', 'hidden');
|
||||
form.appendChild(csrfInput);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue