Appwrite:带帖子的用户权限

问题描述 投票:0回答:1

我刚开始使用 Appwrite,并且找不到添加用户仅查看其帖子的权限的方法。如何将新属性添加到帖子文档作为 user_id

appwrite
1个回答
0
投票

在 Appwrite 集合中创建文档时,您还可以添加文档级权限,以便只有用户才能读取其文档。

这需要两个步骤:

  • 在 Appwrite 控制台中

对于您的数据库集合,设置集合权限,如图所示

如图所示,所有用户都被授予

create
update
delete
权限,但没有
read
。您还必须启用
Document Security

  • 创建文档时

在您的代码库中,当您创建文档时,您必须直接使用 SDK 添加权限。这是一个来自我的个人项目的相同示例,使用 JavaScript (Web SDK)

async function addImage(userId, imageId) {
  return await databases.createDocument(databaseId, 
    collectionId,
    ID.unique(),
    {
      userId: userId,
      imageId: imageId
    },
    [Permission.write(Role.user(userId)), Permission.read(Role.user(userId))]
  );
}

在我们的文档

中了解有关 Appwrite 权限的更多信息
© www.soinside.com 2019 - 2024. All rights reserved.