Skip to content

How to allow SyncData for more complex access #1217

Answered by mpscholten
amitaibu asked this question in Q&A
Discussion options

You must be logged in to vote

A policy set like this should implement the above rules:

CREATE POLICY "Everyone can see all posts" ON posts USING (true) WITH CHECK (false);
CREATE POLICY "Post owners can edit their posts" ON posts USING (true) WITH CHECK (user_id = ihp_user_id());
CREATE POLICY "Admins can edit all posts" ON posts USING (true) WITH CHECK (select is_admin from users where id = ihp_user_id() limit 1);

Check out https://www.postgresql.org/docs/current/sql-createpolicy.html to see what policies can do. It can pretty much cover most advanced use cases. (E.g. while right now not supported in the Schema Designer, you can also have a policy that only applies to e.g. UPDATE queries or only to DELETE queries)

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by amitaibu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants