File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -19,8 +19,16 @@ export function getVerboseName(name) {
1919
2020
2121export function getCsrfCookie ( ) {
22- if ( ( document . cookie . split ( ';' ) . filter ( ( item ) => item . trim ( ) . indexOf ( 'csrftoken=' ) === 0 ) ) . length ) {
23- return document . cookie . split ( ';' ) . filter ( ( item ) => item . trim ( ) . indexOf ( 'csrftoken=' ) === 0 ) [ 0 ] . split ( '=' ) [ 1 ] ;
22+ let csrfCookies = document . cookie . split ( ';' ) . filter ( ( item ) => item . trim ( ) . indexOf ( 'csrftoken=' ) === 0 ) ;
23+
24+ if ( csrfCookies . length ) {
25+ return csrfCookies [ 0 ] . split ( '=' ) [ 1 ] ;
26+ } else {
27+ // if no cookie found, get the value from the csrf form input
28+ let input = document . querySelector ( 'input[name="csrfmiddlewaretoken"]' ) ;
29+ if ( input )
30+ return input . value ;
2431 }
32+
2533 return null ;
2634}
You can’t perform that action at this time.
0 commit comments