© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
3 replies
jdgamble555

RLS Anyone Can Count, but NOT Read

hearts
- pid (fk to posts.id)
- uid (fk to users.id)
(pk = pid + uid)
hearts
- pid (fk to posts.id)
- uid (fk to users.id)
(pk = pid + uid)

I have set up my rules so that only a user can like their own post. Basically all CRUD operations. However, I need ANYONE to be able to count the likes for a post.

Current Rule
(role() = 'authenticated'::text)
AND (uid = uid())
AND (uid() = (SELECT posts.author FROM posts WHERE (posts.id = hearts.pid)))
(role() = 'authenticated'::text)
AND (uid = uid())
AND (uid() = (SELECT posts.author FROM posts WHERE (posts.id = hearts.pid)))


Count Query
// pid is the post id
const q2 = supabase.from('hearts')
  .select('pid', { count: 'exact' })
  .eq('pid', pid);
// pid is the post id
const q2 = supabase.from('hearts')
  .select('pid', { count: 'exact' })
  .eq('pid', pid);

How can I create a rule allowing anyone to be able to ONLY count the total likes, just not CRUD them? Can I do this with an additional rule, or do I need to edit the current one?

Thanks,

J
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

RLS not allowing to read data
SupabaseSSupabase / help-and-questions
2mo ago
RLS, Can not Update and Del
SupabaseSSupabase / help-and-questions
5mo ago
RLS not working
SupabaseSSupabase / help-and-questions
3mo ago
Bucket RLS works for Insert but not Update
SupabaseSSupabase / help-and-questions
13mo ago