create policy "Public profiles are viewable only by authenticated users"
on profiles for select
to authenticated
using ( true );
只有匿名用户
create policy "Public profiles are viewable only by authenticated users"
on profiles for select
to anon
using ( true );
,或者您可以使用内置的auth auth变量来执行其他检查:
认证的用户可以识别用户可以ID匹配匹配的身份验证
alter policy "Users can update their own record"
on "public"."users"
to public
using (
(auth.uid() = id)
);
认证的用户ID未零检查
alter policy "Users can view data"
on "public"."items"
to public
using (
(auth.uid() IS NOT NULL)
);
身份验证的用户角色检查
alter policy "Users can view data"
on "public"."items"
to public
using (
(auth.role() = 'authenticated'::text)
);
Each policy applies to one of the 4 possible database operations (Select, delete, update, insert) so you'll need to create a new policy for updating the table. Adding this here for my future self.
You can use the built-in roles to allow access for authenticated or anonymous users:
Only Authenticated users
create policy "Public profiles are viewable only by authenticated users"
on profiles for select
to authenticated
using ( true );
Only Anonymous users
create policy "Public profiles are viewable only by authenticated users"
on profiles for select
to anon
using ( true );
Or you can use the built-in auth variable to perform other checks:
Authenticated user can ID match check
alter policy "Users can update their own record"
on "public"."users"
to public
using (
(auth.uid() = id)
);
Authenticated user ID not null check
alter policy "Users can view data"
on "public"."items"
to public
using (
(auth.uid() IS NOT NULL)
);
Authenticated user role check
alter policy "Users can view data"
on "public"."items"
to public
using (
(auth.role() = 'authenticated'::text)
);
发布评论
评论(2)
插入策略仅适用于新行。您可能需要为您的表创建单独的更新策略。
这种特定的讨论可能会指向正确的方向:
https://github.com/supabase/supabase/supabase/supabase/discussions/discussions/3476
Insert policy only works for a new row. You would probably need to create a separate update policy for your table.
This specific discussion might point you to the right direction:
https://github.com/supabase/supabase/discussions/3476
每个策略都适用于四个可能的数据库操作之一(选择,删除,更新,插入),因此您需要创建一个新的策略来更新表。在这里添加它以使我的未来自我。
您可以使用允许访问身份验证或匿名用户:
只有身份验证的用户
只有匿名用户
,或者您可以使用内置的auth auth变量来执行其他检查:
认证的用户可以识别用户可以ID匹配匹配的身份验证
认证的用户ID未零检查
身份验证的用户角色检查
Each policy applies to one of the 4 possible database operations (Select, delete, update, insert) so you'll need to create a new policy for updating the table. Adding this here for my future self.
You can use the built-in roles to allow access for authenticated or anonymous users:
Only Authenticated users
Only Anonymous users
Or you can use the built-in auth variable to perform other checks:
Authenticated user can ID match check
Authenticated user ID not null check
Authenticated user role check