Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turbo frame request is removing the csrf meta tag #669

Open
noctivityinc opened this issue Aug 22, 2024 · 0 comments
Open

Turbo frame request is removing the csrf meta tag #669

noctivityinc opened this issue Aug 22, 2024 · 0 comments

Comments

@noctivityinc
Copy link

When doing a simply turbo frame request via a link click, we are noticing the CSRF meta tag is REMOVED from the page!? We are having to do this hack to get it back, which I don't love and seems like a bug:

document.addEventListener("turbo:before-fetch-request", function (event) {
  window.csrfToken = document.querySelector("[name=csrf-token]").content;
  event.detail.fetchOptions.headers["X-CSRF-Token"] = csrfToken;
});

document.addEventListener("turbo:frame-load", function (event) {
  const csrfMetaTag = document.querySelector('meta[name="csrf-token"]');
  if (!csrfMetaTag) {
    const newCsrfMetaTag = document.createElement("meta");
    newCsrfMetaTag.name = "csrf-token";
    newCsrfMetaTag.content = window.csrfToken;
    document.head.appendChild(newCsrfMetaTag);
  }
});
``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant