Firebase-Tools: firestore: удалить ошибку в эмуляторе - PullRequest
0 голосов
/ 05 мая 2020

Я пытаюсь использовать рекурсивное удаление из firebase-tools внутри облачной функции firebase. И я тестирую это с помощью эмулятора.

Но на данный момент я не очень успешен.

Похоже, что интерфейс командной строки использует REST API Firestore. Доступно ли это с эмулятором?

Моя функция такая:

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/kipinto-dev-f7v4:testIamPermissions"
   - Be careful, this may be a production service.
⚠  External network resource requested!
   - URL: "http://tornado.local:3344/v1beta1/projects/kipinto-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/kipinto-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

Спасибо за ваше help!


EDIT 1: кажется, REST API должен работать с эмулятором, поскольку он приведен здесь в качестве примера: https://firebase.google.com/docs/emulator-suite/connect_and_prototype#clear_your_database_between_tests

Я отмечаю, что в В моем случае запрос выполняется на конечной точке v1beta1, когда он выполняется на конечной точке v1 в примере do c.


EDIT 2: следуя рекомендации @sam, я тестировал с non ограничительные правила, и это работает. Но насколько мне известно, облачные функции должны игнорировать правила (#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;
    }
  }
}

1 Ответ

0 голосов
/ 08 мая 2020

Эта ошибка была исправлена ​​командой firebase в этом PR .

...