From 9cf2924f7be838d1442e9bb852afbc7d6faa1b67 Mon Sep 17 00:00:00 2001 From: Dylan Oliver Date: Thu, 17 Mar 2022 22:30:27 -0400 Subject: [PATCH] check presence of window before using it and appease ts types --- src/lib/crypto.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/crypto.ts b/src/lib/crypto.ts index 87011c3d99..fb6cd705a5 100644 --- a/src/lib/crypto.ts +++ b/src/lib/crypto.ts @@ -11,7 +11,11 @@ declare global { } } -const crypto = window.crypto || window.msCrypto || nodeCrypto.webcrypto; +const crypto = + (typeof window !== "undefined" && + (window as Window) && + (window.crypto || window.msCrypto)) || + (nodeCrypto.webcrypto as unknown as Crypto); const subtle: SubtleCrypto = crypto.subtle || crypto.webkitSubtle; if (subtle === undefined) {