Skip to content

Commit

Permalink
fix: isBrowser to include typeof window !== 'undefined' check
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
salmoro committed Nov 19, 2024
1 parent dfb40d2 commit fc258a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fc258a7

Please sign in to comment.