[英]Firebase-Tools : firestore:delete error in Emulator
我正在嘗試在 firebase 雲 function 中使用 firebase-tools 的遞歸刪除。 我正在用模擬器對此進行測試。
但目前,我並不是很成功。
似乎 CLI 正在使用 Firestore REST API。 模擬器可以用嗎?
我的 function 是這樣的:
import * as firebaseTools from 'firebase-tools';
import { db } from './admin';
const DEBUG = true;
export async function deleteUserData(userId) {
if (DEBUG) console.log('Delete user data', userId);
await firebaseTools.firestore.delete(`users/${userId}/contacts/`, {
project: db._projectId,
recursive: true,
yes: true, // auto-confirmation
});
if (DEBUG) console.log('User data deleted', userId);
}
這是來自模擬器的日志:
i functions: Beginning execution of "deleteUserData"
> Delete user data 4AiyOyCnAPSrKhc1Ycf6nVDqLoD2
> i You have set FIRESTORE_EMULATOR_HOST=tornado.local:3344, this command will execute against the firestore emulator running at that address.
⚠ Google API requested!
- URL: "https://cloudresourcemanager.googleapis.com/v1/projects/myapp-dev-f7v4:testIamPermissions"
- Be careful, this may be a production service.
⚠ External network resource requested!
- URL: "http://tornado.local:3344/v1beta1/projects/myapp-dev-f7v4/databases/(default)/documents/users/4AiyOyCnAPSrKhc1Ycf6nVDqLoD2:runQuery"
- Be careful, this may be a production service.
> Error with Delete FirebaseError: Failed to delete documents FirebaseError: HTTP Error: 403,
> Null value error. for 'list' @ L11
> at Timeout.<anonymous> (/Users/pitouli/Documents/GIT/myapp-app/functions/node_modules/firebase-tools/lib/firestore/delete.js:251:28)
> at listOnTimeout (internal/timers.js:549:17)
> at processTimers (internal/timers.js:492:7) {
> name: 'FirebaseError',
> children: [],
> context: undefined,
> exit: 1,
> message: 'Failed to delete documents FirebaseError: HTTP Error: 403, \n' +
> "Null value error. for 'list' @ L11",
> original: undefined,
> status: 500
> }
i functions: Finished "deleteUserData" in ~1s
謝謝你的幫助!
EDIT 1: it seems the REST API should work with the emulator since it's given as example here: https://firebase.google.com/docs/emulator-suite/connect_and_prototype#clear_your_database_between_tests
我注意到,在我的例子中,當請求是在文檔示例中的v1
端點上發出時,它是在v1beta1
端點上發出的。
編輯 2:按照@sam 的建議,我使用非限制性規則進行了測試,並且可以正常工作。 但據我所知,雲功能應該忽略規則(#gangsta)
這是我的“正常”規則:
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 /users/{userId} {
allow read, update, delete: if request.auth.uid == userId;
allow create: if request.auth.uid != null;
}
match /users/{userId}/{document=**} {
allow create, read, update, delete: if request.auth.uid == userId;
}
}
}
這是我用於測試的那些:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
此錯誤已由 firebase 團隊在此 PR中修復。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.