[Glitch] Use vanilla JS to get Rails CSRF values
Port 00d94f3ffa
to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
06881a8669
commit
00d72866a3
|
@ -1,5 +1,3 @@
|
||||||
import Rails from '@rails/ujs';
|
|
||||||
|
|
||||||
import { signOutLink } from 'flavours/glitch/utils/backend_links';
|
import { signOutLink } from 'flavours/glitch/utils/backend_links';
|
||||||
|
|
||||||
export const logOut = () => {
|
export const logOut = () => {
|
||||||
|
@ -11,13 +9,18 @@ export const logOut = () => {
|
||||||
methodInput.setAttribute('type', 'hidden');
|
methodInput.setAttribute('type', 'hidden');
|
||||||
form.appendChild(methodInput);
|
form.appendChild(methodInput);
|
||||||
|
|
||||||
const csrfToken = Rails.csrfToken();
|
const csrfToken = document.querySelector<HTMLMetaElement>(
|
||||||
const csrfParam = Rails.csrfParam();
|
'meta[name=csrf-token]',
|
||||||
|
);
|
||||||
|
|
||||||
|
const csrfParam = document.querySelector<HTMLMetaElement>(
|
||||||
|
'meta[name=csrf-param]',
|
||||||
|
);
|
||||||
|
|
||||||
if (csrfParam && csrfToken) {
|
if (csrfParam && csrfToken) {
|
||||||
const csrfInput = document.createElement('input');
|
const csrfInput = document.createElement('input');
|
||||||
csrfInput.setAttribute('name', csrfParam);
|
csrfInput.setAttribute('name', csrfParam.content);
|
||||||
csrfInput.setAttribute('value', csrfToken);
|
csrfInput.setAttribute('value', csrfToken.content);
|
||||||
csrfInput.setAttribute('type', 'hidden');
|
csrfInput.setAttribute('type', 'hidden');
|
||||||
form.appendChild(csrfInput);
|
form.appendChild(csrfInput);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue