I have a purchases table which connects users to digital products they've purchased.
How do I get RLS set up so that only users who have purchased a product can view the product info?
Somewhat programmatically,
view product_info if purchases has row with product.id and user.id
. Hope that makes sense.
n
Nin
07/22/2022, 8:40 AM
Do you have a user_id column on that table? If so you can do something like user_id=uid()
m
Max52
07/22/2022, 12:50 PM
Well there are 4 tables. Users, purchases, products, and product_info.
I want the user to only have access to the rows in product_info for the products they have purchased.
Max52
07/22/2022, 1:05 PM
User_id is only a FK in the purchases table
n
Nin
07/23/2022, 7:33 PM
Anything that returns true can be used as policy'
Nin
07/23/2022, 7:35 PM
So you could do something like SELECT count(something) FROM product_info
JOIN purchases ON purchases.product_info_id = product_info.product_info_id
WHERE purchases.user_id = uid() >=1