From a4fd6fa9785f54e8ab985c704a5b6fe2793584c2 Mon Sep 17 00:00:00 2001 From: Tadhg O'Higgins <2626258+tadhg-ohiggins@users.noreply.github.com> Date: Thu, 3 Aug 2023 17:35:37 -0700 Subject: [PATCH] We need a null check because even though this isn't called anywhere that doesn't need it, it's still loaded and executed on other pages. --- backend/static/js/csrft.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/static/js/csrft.js b/backend/static/js/csrft.js index dc41745b39..85e72050b5 100644 --- a/backend/static/js/csrft.js +++ b/backend/static/js/csrft.js @@ -1,3 +1,7 @@ export const getCookie = () => { - return document.querySelector('[name=csrfmiddlewaretoken]').value; + const csrfInput = document.querySelector('[name=csrfmiddlewaretoken]'); + if (csrfInput !== null) { + return document.querySelector('[name=csrfmiddlewaretoken]').value; + } + return null; };