Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Supabase keep throwing a http 406 (Not Acceptable) error?

RLS is disabled. Role is anon. Seems like that the necessity right? This is my code using nextjs. I made it works previously, but not sure why it doesn't work now.

const fetchSupabaseUser = async (firebaseUser: FirebaseUser | null) => {
      if (!firebaseUser) return;

      const { data, error, status } = await supabase
        .from('users')
        .select('*')
        .eq('google_id', firebaseUser.uid)
        .single();

      console.log(error, status);

      if (error && status !== 406) {
          console.error("Supabase error:", error);
          throw error
      }
      // if (error) console.error("Supabase error:", error);
      
      if (error && Object.keys(error).length !== 0) {
          if (error instanceof Error) {
              console.error('Error fetching Supabase user:', error.message);
          // } else {
          //   console.error('An unknown error occurred while fetching Supabase user:', error);
          }
          return;
      }

      setUser(data);
      console.log('Supabase user set:', data);
};

In the Chrome console, I see this:

fetch.ts:15 GET https://mkibhcvvghfyxutpsaqe.supabase.co/rest/v1/users?select=*&google_id=eq.mbRwFh8AgLZuSaXCscIIkJNFTBz1 406 (Not Acceptable)

Printing the error:

{
code: 'PGRST116',
details: 'The result contains 0 rows',
hint: null,
message: 'JSON object requested, multiple (or no) rows returned'
}

like image 384
swdev Avatar asked Oct 25 '25 05:10

swdev


1 Answers

Sorry, fixed it. single() will return error if empty (but the error code really misguided). so using maybeSingle() solved this

like image 52
swdev Avatar answered Oct 28 '25 04:10

swdev