supabase更新端点无法与已验证的用户使用

发布于 2025-01-30 17:29:14 字数 249 浏览 6 评论 0 原文

我正在测试Supabase RLS策略,当我尝试使用身份验证的用户更新商店时,我会出现404错误。

但是,当我尝试使用插入时,策略规则是相同的!

I'm testing the Supabase RLS policies and when I try to update a store with an authenticated user I got a 404 error.

enter image description here

But when I try to use insert it works, but the rule of policies is the same!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痴梦一场 2025-02-06 17:29:14

插入策略仅适用于新行。您可能需要为您的表创建单独的更新策略。

这种特定的讨论可能会指向正确的方向:
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

爱人如己 2025-02-06 17:29:14

每个策略都适用于四个可能的数据库操作之一(选择,删除,更新,插入),因此您需要创建一个新的策略来更新表。在这里添加它以使我的未来自我。

您可以使用允许访问身份验证或匿名用户:

”

只有身份验证的用户

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:

Supabase target roles

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)
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文