mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: do not log CSRF error in Electron environments (#21054)
Closes #20914
This commit is contained in:
+6
-3
@@ -2783,15 +2783,18 @@ function getConfiguredAxiosInstance(): AxiosInstance {
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
// Development mode uses a hard-coded CSRF token
|
||||
instance.defaults.headers.common["X-CSRF-TOKEN"] = csrfToken;
|
||||
instance.defaults.headers.common["X-CSRF-TOKEN"] = csrfToken;
|
||||
tokenMetadataElement.setAttribute("content", csrfToken);
|
||||
} else {
|
||||
instance.defaults.headers.common["X-CSRF-TOKEN"] =
|
||||
tokenMetadataElement.getAttribute("content") ?? "";
|
||||
}
|
||||
} else {
|
||||
// Do not write error logs if we are in a FE unit test.
|
||||
if (!process.env.JEST_WORKER_ID && !process.env.VITEST) {
|
||||
// Do not write error logs if we are in a FE unit test or if there is no document (e.g., Electron)
|
||||
if (
|
||||
typeof document !== "undefined" &&
|
||||
!process.env.JEST_WORKER_ID &&
|
||||
!process.env.VITEST
|
||||
) {
|
||||
console.error("CSRF token not found");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user