From 00d94f3ffabda89a2f955212e763cdba3f1f54c6 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 12 Mar 2024 13:10:37 -0400 Subject: [PATCH] Use vanilla JS to get Rails CSRF values (#29403) --- app/javascript/mastodon/utils/log_out.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/javascript/mastodon/utils/log_out.ts b/app/javascript/mastodon/utils/log_out.ts index 3a4cc8ecb..b08a61a6a 100644 --- a/app/javascript/mastodon/utils/log_out.ts +++ b/app/javascript/mastodon/utils/log_out.ts @@ -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( + 'meta[name=csrf-token]', + ); + + const csrfParam = document.querySelector( + '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); }