Skip to content

Commit 14b3717

Browse files
Merge pull request #442 from laravel/revert-csrf-logic
Revert CSRF logic
2 parents 453dc84 + 02c56a5 commit 14b3717

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

packages/laravel-echo/src/connector/connector.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,26 @@ export abstract class Connector<
9090
* Extract the CSRF token from the page.
9191
*/
9292
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;
101113
}
102114

103115
/**

0 commit comments

Comments
 (0)