Skip to content

Commit

Permalink
Adjusted logic of csrf setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mkimberlin committed Nov 5, 2024
1 parent 4399622 commit 6f87de8
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions web-ui/src/context/AppContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6f87de8

Please sign in to comment.