【发布时间】:2020-11-26 11:23:01
【问题描述】:
我们可以使用经过身份验证的用户的 UID 安全地查询文档,使用这样的 Firestore 规则:
service cloud.firestore {
match /databases/{database}/documents {
match /stories/{storyid} {
// Only the authenticated user who authored the document can read or write
allow read, write: if request.auth != null && request.auth.uid == resource.data.author;
}
}
}
但我找不到如何使用经过身份验证的用户 UID 填充数据。
以下文档工作正常,但它是从客户端发送的,我认为它不安全,因为请求可能已篡改了另一个用户 UID。
{
title: "A Great Story",
content: "Once upon a time...",
author: user.uid,
published: false
}
基本上,我需要来自 Firebase 服务器的用户 UID 值,就像我们可以使用 firestore.FieldValue.serverTimestamp() 从服务器插入时间戳一样
【问题讨论】:
标签: firebase google-cloud-firestore firebase-security