Skip to content

fix(auth): avoid window.location access in SSR environments #1074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gonchantech
Copy link

What kind of change does this PR introduce?

Bug fix.

What is the current behavior?

When creating a Supabase client on the server side, the _initialize() method tries to access window.location.href, causing a ReferenceError and crashing the process. As a result, the method this.recoverAndRefresh responsible for restoring and refreshing the authentication state does not get called properly. other methods may recover the session later, so this doesn’t immediately break all functionality. However, this still represents an inconsistent design: recoverAndRefresh() is server-compatible, yet it's gated behind a browser-only execution path.

What is the new behavior?

This change adds a check using isBrowser() to avoid accessing window.location.href on the server side by providing empty parameters instead. This prevents the crash and allows this.recoverAndRefresh to be called correctly, enabling proper restoration and refreshing of the authentication state in server-side environments.

Additional context

Closes #1073

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ReferenceError: window is not defined crash in GoTrueClient _initialize() on server-side environments
1 participant