Firebase-Tools:firestore:delete 模拟器错误
Firebase-Tools : firestore:delete error in Emulator
我正在尝试在 firebase 云函数中使用 firebase-tools 的递归删除。我正在用模拟器对此进行测试。
但目前我还不是很成功
CLI 似乎正在使用 Firestore REST API。模拟器可用吗?
我的函数是这样的:
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
感谢您的帮助!
编辑 1:似乎 REST API 应该与模拟器一起工作,因为它在此处作为示例给出:https://firebase.google.com/docs/emulator-suite/connect_and_prototype#clear_your_database_between_tests
我注意到,在我的例子中,请求是在 v1beta1
端点上发出的,而在文档示例中它是在 v1
端点上发出的。
编辑 2:按照@sam 的建议,我使用非限制性规则进行了测试,并且有效。但据我所知,Cloud Functions 应该忽略规则 (#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 团队在 this PR 中修复。
我正在尝试在 firebase 云函数中使用 firebase-tools 的递归删除。我正在用模拟器对此进行测试。
但目前我还不是很成功
CLI 似乎正在使用 Firestore REST API。模拟器可用吗?
我的函数是这样的:
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
感谢您的帮助!
编辑 1:似乎 REST API 应该与模拟器一起工作,因为它在此处作为示例给出:https://firebase.google.com/docs/emulator-suite/connect_and_prototype#clear_your_database_between_tests
我注意到,在我的例子中,请求是在 v1beta1
端点上发出的,而在文档示例中它是在 v1
端点上发出的。
编辑 2:按照@sam 的建议,我使用非限制性规则进行了测试,并且有效。但据我所知,Cloud Functions 应该忽略规则 (#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 团队在 this PR 中修复。