DEV Community

Cojiroooo
Cojiroooo

Posted on

supabase.from().select() finished unexpectedly and doesn't occur any errors

Problem

I write the below, but it doesn't occur any errors and the process terminated prematurely.
At the first time after the server started, that was successful, but that happen after the reload browser.

supabase.auth.onAuthStateChange(async (event, session) => {
  // ...
  const { data, error } = await supabase.from("table_name").select(); // the process finished
  // ...
});
Enter fullscreen mode Exit fullscreen mode

Causes

I found the answer to this problem in the document.

Do not use other Supabase functions in the callback function. If you must, dispatch the functions once the callback has finished executing. Use this as a quick way to achieve this:

https://supabase.com/docs/reference/javascript/auth-onauthstatechange

Solution

I wanted to fetch the user information when users authentication was successful.

const afterSignedIn = async () => {
  const { data, error } = await supabase.from("users").select();
};

supabase.auth.onAuthStateChange((event, session) => {
  // ...
  setTimeout(() => {
    afterSignedIn();
  }, 0);
});


Enter fullscreen mode Exit fullscreen mode

Top comments (0)