I set up a basic RLS policy on a new table I creat...
# help
t
I set up a basic RLS policy on a new table I created, called client_profiles. The policy is for select, and the rule is simple: (uid() = agent_id), yet, I'm getting no items back now. I guess more my question is how can I troubleshoot to see WHY rls failed or "chose to protect"...is there anywhere I can see why maybe the ids aren't matching, etc?
n
Hello @tandyman! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
g
I would first turn RLS off, does it work?, then if it does set policy to (auth.role() = 'anon'). If that works then you are not logged in. Next (auth.role() = 'authenticated'). If that works you have a user. Then with your policy if agent_id is a uuid column and there is a match, you should get a result.
n
tandyman (2022-03-27)
t
ok
off = yes
i'll move to the next
anon yes
g
Stop
You don't have a logged in user.
t
what do you mean?
g
If anon works, then you don't have a signed in user, or when you make the call you do not.
t
anon works, and authenticated fails
in the nextJS app, I am logged in
so there's the disconnect?
g
If anon works that means there is no token set in the header for the call. Yes there is a disconnect
uid() will be null as there is no user token when you make the call.
t
hmm
so now I have to find why
I'm using a stripe starter repo and have been building on top of that, so all of that I thought was handled already
there is a useUser() hook, etc
const { data: clientProfiles, error } = await supabaseClient .from('client_profiles') .select(
*
)
so supabaseClient isn't adding the token?
g
Do you have a signin process?
t
yes
and it's signed in
on every page load I see the user object being returned after it does a GET on the user endpoint
g
The threads are full of nextjs stuff and I don't use it, but know it is a bit tricky dealing with signin on server side... Most seem to be drifting to this: https://github.com/supabase-community/supabase-auth-helpers BUT I DON'T want to steer you wrong... Do some searching here or discussions on github and re ask about nextjs and no user when you make call or some such. You are not at RLS issue yet.
t
ahh
apparently that is what is being used already
import { withAuthRequired, supabaseClient } from '@supabase/supabase-auth-helpers/nextjs';
so that is where i'm getting supabaseClient
g
Sorry can't be more help with nextjs.
t
that's ok, it's a great answer though, so show me layer by layer how to approach
that helps me "fish"
much appreciated sir 🍷
you are exactly right, their readme covers directions specifically when making the call server side...and that starter project was not implemented with an example ready to handle with RLS
worked!
g
My role as traffic cop paid off... 👍
t
hahaha