Skip to content

Commit 6d0084c

Browse files
committed
Adjusted logic of csrf setting
1 parent 9e96e6a commit 6d0084c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

web-ui/src/context/AppContext.jsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,19 @@ const AppContextProvider = props => {
7474
const url = `${BASE_API_URL}/csrf/cookie`;
7575
useEffect(() => {
7676
const getCsrf = async () => {
77-
const cookieVal = getSessionCookieValue('_csrf');
78-
if (!csrf && !cookieVal) {
79-
const res = await fetch(url, {
80-
responseType: 'text',
81-
credentials: 'include'
82-
});
83-
if (res && res.ok) {
84-
dispatch({ type: SET_CSRF, payload: await res.text() });
77+
if (!csrf) {
78+
const payload = getSessionCookieValue('_csrf');
79+
if (payload) {
80+
dispatch({ type: SET_CSRF, payload });
81+
} else {
82+
const res = await fetch(url, {
83+
responseType: 'text',
84+
credentials: 'include'
85+
});
86+
if (res && res.ok) {
87+
dispatch({ type: SET_CSRF, payload: await res.text() });
88+
}
8589
}
86-
} else if (cookieVal) {
87-
dispatch({ type: SET_CSRF, payload: cookieVal });
8890
}
8991
};
9092
getCsrf();

0 commit comments

Comments
 (0)