I have looked at various solutions on StackOverflow, github issues in supabase, supabase/postgrest-js, postgRESTPostgREST/postgrest, and searched the Discord as well. But none of the solutions have been working so far.
The code works as expected, but as soon as I turn on RLS on Supabase. The request will return the below 406 error.
export const supabase = createClient(process.env.NEXT_PUBLIC_SUPABASE_URL, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY)
const { data, error } = await supabase.from('profiles').select('*').eq('id', userId).maybeSingle()
// const { data, error } = await supabase.from('profiles').select('*').eq('id', userId).limit(1).single() // works when RLS disabled
// const { data, error } = await supabase.from('profiles').select('*').eq('id', userId).single() // works when RLS disabled
Response before RLS
{
"id": "123-123-1241-1231",
"created_at": "2022-06-10T03:59:22.751125+00:00",
"is_subscribed": false,
"interval": null,
"email": "test@example.com"
}
Response after turning on RLS
{
"message": "JSON object requested, multiple (or no) rows returned",
"details": "Results contain 0 rows, application/vnd.pgrst.object+json requires 1 row"
}
I've tried schema reload, re-implement the policy, but none's been working so far.
I have a "profile" table its "id" column referencing the "auth.users.id".
The policy's target role is currently "anon" but I've tried "authenticated" as well.
(uid() = id)
I also tried to change the table name to "profiles" (plural) instead of "profile" but no luck.