最近我在一個平臺上作業,遇到了一個問題,我想比較存盤在用戶資料庫中的時間戳和 Firebase 規則中的請求時間。這樣一來,只有在他/她在特定時間后請求時,他/她才能閱讀檔案。
這是迄今為止我嘗試使用的代碼。
注意:欄位名strton是指資料庫檔案中的時間戳物件。
match /tests/{testsID}{
match /response/{responseID}{
allow read: if get(/databases/$(database)/documents/tests/{testID}).data.strton < request.time;
}
}
match /tests/{testsID}{
match /response/{responseID}{
allow read: if get(/databases/$(database)/documents/tests/{testID}).data.strton.toMillis() < request.time.toMillis();
}
}
感謝您對我如何實作這一目標的任何幫助。
更新:這是檔案結構(私人資訊已被審查)
和試圖訪問它的代碼
docRef = doc(db, "tests", testid,"responses",auth.currentUser.uid);
docSnap = await getDoc(docRef);
if (docSnap.exists()) {
testResponseList = docSnap.data()
}else {
await setDoc(doc(db, "tests", testid,"responses",auth.currentUser.uid), {
answers:[]})
還有一件事是該代碼試圖獲取的檔案現在不存在。如果檔案不存在,則 Else 陳述句用于制作檔案。但是 else 陳述句沒有被執行。
uj5u.com熱心網友回復:
您正在使用帶有in{wildcard}的檔案路徑中使用的運算式語法。相反,您應該使用./matchget()$(testsID)
還有一些拼寫錯誤:
- 您的收藏名稱是
responses,但您有response規則 - 它
testsID在通配符中,但你有testID
嘗試重構規則,如下所示:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /tests/{testID} {
match /responses/{responseID} {
allow read: if get(/databases/$(database)/documents/tests/$(testID)).data.strton < request.time;
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/454469.html
標籤:火力基地 谷歌云火库 firebase-安全
上一篇:OSError:[Errno8]Execformaterror:'/home/ec2-user/Desktop/chromedriver'在AWSEC2ARM風味機器中使用Chro
