Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda