File tree Expand file tree Collapse file tree 1 file changed +20
-8
lines changed
packages/laravel-echo/src/connector Expand file tree Collapse file tree 1 file changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -90,14 +90,26 @@ export abstract class Connector<
90
90
* Extract the CSRF token from the page.
91
91
*/
92
92
protected csrfToken ( ) : null | string {
93
- return (
94
- window ?. Laravel ?. csrfToken ??
95
- this . options . csrfToken ??
96
- document
97
- ?. querySelector ( 'meta[name="csrf-token"]' )
98
- ?. getAttribute ( "content" ) ??
99
- null
100
- ) ;
93
+ if ( typeof window !== "undefined" && window . Laravel ?. csrfToken ) {
94
+ return window . Laravel . csrfToken ;
95
+ }
96
+
97
+ if ( this . options . csrfToken ) {
98
+ return this . options . csrfToken ;
99
+ }
100
+
101
+ if (
102
+ typeof document !== "undefined" &&
103
+ typeof document . querySelector === "function"
104
+ ) {
105
+ return (
106
+ document
107
+ . querySelector ( 'meta[name="csrf-token"]' )
108
+ ?. getAttribute ( "content" ) ?? null
109
+ ) ;
110
+ }
111
+
112
+ return null ;
101
113
}
102
114
103
115
/**
You can’t perform that action at this time.
0 commit comments