beepboop
06/17/2022, 4:48 AMjs
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
js
{
"id": "123-123-1241-1231",
"created_at": "2022-06-10T03:59:22.751125+00:00",
"is_subscribed": false,
"interval": null,
"email": "scott.tj.yu@gmail.com"
}
Response after turning on RLS
js
{
"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.Needle
06/17/2022, 4:48 AMgaryaustin
06/17/2022, 5:02 AMbeepboop
06/17/2022, 6:01 AMthe access_token
with supabase.auth.setAuth(access_token)
after initializing createClient(URL, ANON_KEY)
and it works. Thanks a ton!
Would you want to paste the answer on StackOverflow since I asked there too?
https://stackoverflow.com/questions/72654424/406-json-object-requested-multiple-or-no-rows-when-rls-is-enabled-on-supabase
If not, I can just answer my own question. Thanks again!Needle
06/18/2022, 12:47 AM