File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed
Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff 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 ( ) ;
You can’t perform that action at this time.
0 commit comments