From 6f87de8f6048e9910f792bf5afd83a655b299bb4 Mon Sep 17 00:00:00 2001 From: Michael Kimberlin Date: Tue, 5 Nov 2024 13:25:15 -0600 Subject: [PATCH] Adjusted logic of csrf setting --- web-ui/src/context/AppContext.jsx | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/web-ui/src/context/AppContext.jsx b/web-ui/src/context/AppContext.jsx index 0bd2819d0b..bd08fc7dc2 100644 --- a/web-ui/src/context/AppContext.jsx +++ b/web-ui/src/context/AppContext.jsx @@ -74,17 +74,19 @@ const AppContextProvider = props => { const url = `${BASE_API_URL}/csrf/cookie`; useEffect(() => { const getCsrf = async () => { - const cookieVal = getSessionCookieValue('_csrf'); - if (!csrf && !cookieVal) { - const res = await fetch(url, { - responseType: 'text', - credentials: 'include' - }); - if (res && res.ok) { - dispatch({ type: SET_CSRF, payload: await res.text() }); + if (!csrf) { + const payload = getSessionCookieValue('_csrf'); + if (payload) { + dispatch({ type: SET_CSRF, payload }); + } else { + const res = await fetch(url, { + responseType: 'text', + credentials: 'include' + }); + if (res && res.ok) { + dispatch({ type: SET_CSRF, payload: await res.text() }); + } } - } else if (cookieVal) { - dispatch({ type: SET_CSRF, payload: cookieVal }); } }; getCsrf();