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

105
Visualizações
Timestamp validation Firestore

I use Firestore v9 in React project. I'm trying to add an item with a creation date. I want to make sure that the date is up to date and the user has not changed it.

My add function:

import { collection, addDoc, Timestamp } from "firebase/firestore";

    const startSignal = async () => {
            try {
                const docRef = await addDoc(collection(db, "signals"), {
                    active: true,
                    createdAt: Timestamp.now()
                });
                console.log(docRef);
            } catch (e) {
                console.log("error");
                console.log(e);
            }
        }

My firestore rules:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /signals/{document=**} {
      allow write: if request.auth != null && request.resource.data.createdAt == request.time;
    }
  }
}

When I try to add, I get a refusal. I think that at the time of execution and processing of the request, the time does not match.

How can I make sure that the request has the correct time?

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

0

The only value that always equals request.time in security rules is the token returned by serverTimestamp(). serverTimestamp() is discussed in the documentation.

import { serverTimestamp } from "firebase/firestore";

const docRef = await addDoc(collection(db, "signals"), {
    active: true,
    createdAt: serverTimestamp()
});
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