【发布时间】:2019-03-04 07:04:43
【问题描述】:
我的数据库设置为 /clients 并使用 firebase auth 来处理用户。我想让它让用户只能查看、编辑和删除他们创建的客户端数据。当前的 Firestore 安全规则是。
[code]service cloud.firestore {
match /databases/{database}/documents {
// Make sure the uid of the requesting user matches name of the user
// document. The wildcard expression {userId} makes the userId variable
// available in rules.
match /clients/{userId} {
allow read, update, delete: if request.auth.uid == userId;
allow create: if request.auth.uid != null;
}
}
}[/code]
使用此规则,用户可以将新客户端添加到数据库中,但网站上的客户端不会显示。我有代码设置,以便当用户添加客户端时,它将用户 UID 附加到“userId”下的客户端。显示客户端的代码是
[code]<tbody>
{clients.map(client => (
<tr key={client.id}>
<td>{client.firstName} {client.lastName}</td>
<td>{client.dateCreated}</td>
<td><a href={`tel:${client.phone}`}>{client.phone}</a></td>
<td>
<Link to={`/client/${client.id}`} className="btn btn-secondary btn-sm">
<i className="fas fa-arrow-circle-right"></i> Details
</Link>
</td>
</tr>
))}
</tbody>
[/代码]
我不确定我做错了什么,是安全规则还是我选择显示数据的方式?
【问题讨论】:
标签: reactjs firebase-authentication firebase-security