[SOLVED] Does anyone know what the rls policy for ...
# help
g
[SOLVED] Does anyone know what the rls policy for a SELECT would look like where the user should only be able to get their own data? The table they are selecting from has a
user_id
property that contains their id
n
Hello @GHOST! 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.
s
(auth.uid() = user_id)
n
GHOST (2022-03-21)
g
I tried this but it didn't seem to work unfortunately
if I do a query such as:
Copy code
js
await supabase
            .from('user_profile')
            .select('first_name')
            .eq('user_id', user.id);
I get a
{ data: [], error: null }
response
but it works if I set the rls for select to
true
s
If you have an RLS policy for
user_id
, you don't also need
.eq('user_id', user.id)
in your query - RLS will only return rows that match the conditions specified by the policy. If you set the policy to
true
, it's going to allow any user, authorised or not, to access the entire table. Make sure your
user.id
is the same as the
user_id
of at least 1 of the rows in the table. Content should be identical, but the type should also be identical (i.e.
user.id
is a UUID, so
user_id
should also be UUID)
g
> Make sure your user.id is the same as the user_id of at least 1 of the rows in the table. Content should be identical, but the type should also be identical (i.e. user.id is a UUID, so user_id should also be UUID) this is definately done
> If you set the policy to true, it's going to allow any user, authorised or not, to access the entire table. Ooh I wonder if it's authenticating the user - currently getting this data server side so might not be authenticating
yea it works on client so it's a authentication issue
thank you for the help
n
Thread was archived by . Anyone can send a message to unarchive it.