From fc258a72efe6611d754de56021378cc5947582ea Mon Sep 17 00:00:00 2001 From: Shlomo Morosow Date: Tue, 19 Nov 2024 14:35:59 -0500 Subject: [PATCH] fix: isBrowser to include typeof window !== 'undefined' check There are several checks in GoTrueClient.ts that check window?.[prop] after checking isBrowser() which throws an error in node environments that have "document" defined but not "window". So this is the most minimal check to be sure they don't throw by ensuring "window" is defined. --- src/GoTrueClient.ts | 6 +++++- src/lib/helpers.ts | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/GoTrueClient.ts b/src/GoTrueClient.ts index 0e0c880d8..5aafb625b 100644 --- a/src/GoTrueClient.ts +++ b/src/GoTrueClient.ts @@ -1524,9 +1524,13 @@ export default class GoTrueClient { * Checks if the current URL contains parameters given by an implicit oauth grant flow (https://www.rfc-editor.org/rfc/rfc6749.html#section-4.2) */ private _isImplicitGrantFlow(): boolean { + if (!isBrowser()) { + return false + } + const params = parseParametersFromURL(window.location.href) - return !!(isBrowser() && (params.access_token || params.error_description)) + return !!(params.access_token || params.error_description) } /** diff --git a/src/lib/helpers.ts b/src/lib/helpers.ts index 22e22c978..d940d1b42 100644 --- a/src/lib/helpers.ts +++ b/src/lib/helpers.ts @@ -14,7 +14,8 @@ export function uuid() { }) } -export const isBrowser = () => typeof document !== 'undefined' +export const isBrowser = () => + typeof window !== 'undefined' && typeof document !== 'undefined' const localStorageWriteTests = { tested: false,