Skip to content
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

Can't insantiate Supabase client; fails with GoTrue error "window is not defined." #1249

Open
Stokestack opened this issue Jul 20, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@Stokestack
Copy link

Bug report

  • [x ] I confirm this is a bug with Supabase, not with my own application.
  • [x ] I confirm I have searched the Docs, GitHub Discussions, and Discord.

There is a similar-sounding and possibly related bug here: #786
But the workaround appears to be React-specific and doesn't seem to address the underlying problem.

Describe the bug

I wrote a Deno-based server that is attempting to use Supabase. Upon attempting to insantiate the Supabase client, the application stops with an assertion thrown from GoTrueClient.js, _isImplicitGrantFlow():

In GoTrueClient.js, _isImplicitGrantFlow()

Exception has occurred: ReferenceError: window is not defined
  at SupabaseAuthClient._isImplicitGrantFlow (file:///Users/stokestack/Library/Caches/deno/npm/registry.npmjs.org/@supabase/auth-js/2.64.2/dist/main/GoTrueClient.js:1138:62)
    at SupabaseAuthClient._initialize (file:///Users/stokestack/Library/Caches/deno/npm/registry.npmjs.org/@supabase/auth-js/2.64.2/dist/main/GoTrueClient.js:170:64)
    at file:///Users/stokestack/Library/Caches/deno/npm/registry.npmjs.org/@supabase/auth-js/2.64.2/dist/main/GoTrueClient.js:155:35
    at file:///Users/stokestack/Library/Caches/deno/npm/registry.npmjs.org/@supabase/auth-js/2.64.2/dist/main/GoTrueClient.js:749:36
    at SupabaseAuthClient.lockNoOp [as lock] (file:///Users/stokestack/Library/Caches/deno/npm/registry.npmjs.org/@supabase/auth-js/2.64.2/dist/main/GoTrueClient.js:33:18)
    at SupabaseAuthClient._acquireLock (file:///Users/stokestack/Library/Caches/deno/npm/registry.npmjs.org/@supabase/auth-js/2.64.2/dist/main/GoTrueClient.js:745:31)
    at file:///Users/stokestack/Library/Caches/deno/npm/registry.npmjs.org/@supabase/auth-js/2.64.2/dist/main/GoTrueClient.js:154:31
    at SupabaseAuthClient.initialize (file:///Users/stokestack/Library/Caches/deno/npm/registry.npmjs.org/@supabase/auth-js/2.64.2/dist/main/GoTrueClient.js:157:11)
    at new GoTrueClient (file:///Users/stokestack/Library/Caches/deno/npm/registry.npmjs.org/@supabase/auth-js/2.64.2/dist/main/GoTrueClient.js:136:14)
    at new SupabaseAuthClient (https://jsr.io/@supabase/supabase-js/2.44.3/src/lib/SupabaseAuthClient.ts:6:5)

To Reproduce

Set up a local-development environment for Supabase, and populate its public DB schema with a few tables. Run the Supabase TypeScript type generation on it and direct the output to DBTypes.ts in the source directory struture of any Deno project.

In that Deno project, try this:

import { createClient } from 'jsr:@supabase/supabase-js@2';
import { Database, Tables, Enums, TablesInsert, TablesUpdate } from './DBTypes.ts';

export const supabase = createClient<Database>('http://localhost:54321', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0')

Expected behavior

The client is created and I can start executing queries with it.

Screenshots

Screenshot 2024-07-20 at 2 34 39 PM

System information

  • OS: [e.g. macOS, Windows]
    Mac OS version 14.5

  • Browser (if applies) [e.g. chrome, safari]
    N.A.

  • Version of supabase-js: [e.g. 6.0.2]
    I guess version 2, based on the import statement I'm using.

  • Version of Node.js: [e.g. 10.10.0]
    N.A.

Additional context

Obviously this is a show-stopper.

@Stokestack Stokestack added the bug Something isn't working label Jul 20, 2024
@j4w8n
Copy link
Contributor

j4w8n commented Jul 22, 2024

Looks like this got resolved on Discord:

I'm not familiar with how you're using Deno, but if you add this option to your client, you shouldn't see the error. It's implying that you aren't doing implicit auth (and maybe you don't need auth anyway), and therefore won't call the _isImplictGrantFlow code.

const supabase = createClient(url, key, {
  auth: {
    detectSessionInUrl: false
  }
})

@Stokestack
Copy link
Author

Stokestack commented Jul 22, 2024

Thanks. I wouldn't say it's resolved, though, because this outcome isn't documented (as far as I've seen). If you invoke the client as documented, it fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants