supabase / supabase-js

An isomorphic Javascript client for Supabase. Query your Supabase database, subscribe to realtime events, upload and download files, browse typescript examples, invoke postgres functions via rpc, invoke supabase edge functions, query pgvector.
https://supabase.com
MIT License
3.27k stars 271 forks source link

{ "code": 400, "error_code": "validation_failed", "msg": "Unsupported logout scope \"window\"" } #1227

Open YA9 opened 5 months ago

YA9 commented 5 months ago

Bug report

Describe the bug

When I try supabase.auth.signOut(), on version 2.43.3 on JS, I get this error: { "code": 400, "error_code": "validation_failed", "msg": "Unsupported logout scope "window"" }

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. In a deployed production environment only, when I run supabase.auth.signOut(), I get the error above. In development, before compiling, it works fine.
  2. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

image

System information

YA9 commented 5 months ago

I found a fix for this. It doesn't make sense why this works, but

 supabase.auth
      .signOut({ scope: 'local' })

putting scope local, instead of leaving it empty worked. Seems like there's an error with scope global

YA9 commented 5 months ago

There's still another issue relating to this. When upgrading to the latest version: 2.43.5, everything breaks and I get this error:

Screenshot 2024-06-19 192313

On version 2.43.2, I don't get this error, and things work fine in production.

bcurioous commented 4 months ago

Having the same issue, I faced both the issue mentioned here.

bcurioous commented 4 months ago

I found a solution to the issue. Check your build configuration steps. In my case, I was using Vite.js, which had a global: 'window' transformation configuration. Commenting out that line prevents the global keyword from being transformed into window.

The Supabase-JS client code uses a global object. However, during the Vite.js build, this was being converted to window. In the browser, the window object refers to the document object, which does not contain the global values, leading to the breakage.

Here's the updated configuration:

export default defineConfig({
  define: {
//    global: 'window',
  },
  // other configurations
});

This change resolved the issue for me. If you need further assistance, feel free to ask!