Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
Deleting and updating docs for firestore security rules in local emulator

Using the local emulator, I'm trying to test a rule for my delete & update which looks like this:

match /posts/{postId} {
  allow read: if true;
  allow create: if true;
  allow delete, update: if (resource.data.user.uid == request.auth.uid)
}

In my test file, I write the path of the exact location of the existing doc that I'm trying to perform for example a delete on:

  it("If creator, Allow delete/update items in the post/comment collection", async () => {
    const db = firebase
      .initializeTestApp({ projectId: MY_PROJECT_ID, auth: myAuth })
      .firestore();
    const testDoc = db
      .collection("general")
      .doc("spaces")
      .collection("spaces")
      .doc("9LbUetZxWeL1ln5hv9ug")
      .collection("posts")
      .doc("RtUnezdAgXUfWmRSPpkF");
    await firebase.assertSucceeds(testDoc.delete());
  });

However when I run this test, it gives me this error. However, I know this doc exists and so does the user.uid I am looking to grab in my resource. Is there something wrong in how I'm trying to use this emulator?

I also saw that if I go into my local emulator firestore database, I can hard-code a file, specifically call route my test to it, then it works. enter image description here

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It looks like no user is signed in when you run the test.

Since your security rules check request.auth.uid, they reject the operation when request.auth is null. Check myAuth.currentUser.uid before running the test to ensure it has a value.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda