Skip to content

Using authentication policies with views #901

Discussion options

You must be logged in to vote

Edit: For PostgreSQL 15, this now is supported natively with security invoker views:

CREATE VIEW sorted_titles WITH (security_invoker) as SELECT title FROM posts ORDER BY title;

Edit: The below answer is for projects with PostgreSQL <= 14

However, this query will now returns everyone's posts, not just a user's own post.
CREATE VIEW sorted_titles as SELECT title FROM posts ORDER BY title;

Yes, this is a quirk of how views work. They're called with the privileges of the role that created them(the owner). If you did CREATE VIEW through the SQL Editor, then the owner is supabase_admin and that role is a SUPERUSER(it bypasses RLS).

To fix this you can change the view's owner with:

ALTER VIEW

Replies: 3 comments 16 replies

Comment options

You must be logged in to vote
8 replies
@steve-chavez
Comment options

@vishwasnavadak
Comment options

@steve-chavez
Comment options

@vishwasnavadak
Comment options

@igorlanko
Comment options

Answer selected by Nick-Mazuk
Comment options

You must be logged in to vote
8 replies
@vishwasnavadak
Comment options

@srossross
Comment options

@vishwasnavadak
Comment options

@srossross
Comment options

@srossross
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet