Search code examples
next.jsvercelsupabase

Supabase returning "JSON object requested, multiple (or no) rows returned" in production (vercel)


I am using a tech stack consisting of Next.js 13 and Supabase. In local development, I can fetch the data properly; however, in production, the same query returns empty data or the error message "JSON object requested, multiple (or no) rows returned." I have double-checked environment variables and configurations, and there is nothing wrong there.

I fetch data from Supabase using Next.js's API and then use those endpoints within my frontend to hide/process sensitive data.

I've already tried integrating Vercel and Supabase, using the same variables that these services provided. I believe I have proper Row-Level Security (RLS) policies in place, as they work as intended in local development.

Table RLS Policy Example All the tables have similar RLS policy.

As per the RLS Policy:

  • All SELECT queries have anon and authenticated rules, which, according to the documentation, should be sufficient for reading data without the need for authentication.
  • All other types of requests are reserved for the authenticated role.

Solution

  • The error message you are facing suggests that you are using .single() in your query, yet the query returns multiple or no rows. When you use .single() on your query, you have to make sure the query returns 1 and only 1 row. Using filters and / or limits.