Skip to content

Commit 5224355

Browse files
authored
fix: do not log CSRF error in Electron environments (#21054)
Closes #20914
1 parent 4d15b30 commit 5224355

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

site/src/api/api.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,15 +2783,18 @@ function getConfiguredAxiosInstance(): AxiosInstance {
27832783
if (process.env.NODE_ENV === "development") {
27842784
// Development mode uses a hard-coded CSRF token
27852785
instance.defaults.headers.common["X-CSRF-TOKEN"] = csrfToken;
2786-
instance.defaults.headers.common["X-CSRF-TOKEN"] = csrfToken;
27872786
tokenMetadataElement.setAttribute("content", csrfToken);
27882787
} else {
27892788
instance.defaults.headers.common["X-CSRF-TOKEN"] =
27902789
tokenMetadataElement.getAttribute("content") ?? "";
27912790
}
27922791
} else {
2793-
// Do not write error logs if we are in a FE unit test.
2794-
if (!process.env.JEST_WORKER_ID && !process.env.VITEST) {
2792+
// Do not write error logs if we are in a FE unit test or if there is no document (e.g., Electron)
2793+
if (
2794+
typeof document !== "undefined" &&
2795+
!process.env.JEST_WORKER_ID &&
2796+
!process.env.VITEST
2797+
) {
27952798
console.error("CSRF token not found");
27962799
}
27972800
}

0 commit comments

Comments
 (0)