Navigation

    MemFireDB论坛

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    小技巧,访问权限控制的条件参数

    MemFireDB新手区
    1
    1
    11
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      MemFireDB Robot last edited by

      auth.role()

      auth.role()函数用于获取向数据库发出请求的用户的当前角色;
      可以是下列之一:已认证的(authenticated),匿名的(anon),或你定义的自定义角色。

      • 仅允许身份验证用户启用访问权限
      Create POLICY "策略名称"
      ON public."表名"
      AS PERMISSIVE
      FOR SELECT
      USING( auth.role() = 'authenticated')
      

      auth.email()

      auth.email()函数用于获取向数据库发出请求的用户的电子邮件。这个函数可以在策略中使用,根据用户的电子邮件限制或允许访问某些表或行。

      • 根据电子邮件为用户启用权限
      Create POLICY "策略名称"
      ON public."表名"
      AS PERMISSIVE
      FOR SELECT
      USING( auth.email() = "email" ) ;
      

      auth.uid()

      auth.uid()函数用于获取向数据库提出请求的用户的唯一标识符(UID)。这个函数可以在策略中使用,根据用户的UID限制或允许访问某些表或行。

      • 根据用户ID为用户启用访问权限
      Create POLICY "策略名称"
      ON public."表名"
      AS PERMISSIVE
      FOR SELECT
      USING( auth.uid() = "id" ) ;
      
      1 Reply Last reply Reply Quote 1
      • First post
        Last post