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

189
Vistas
Multiple Variations of Firebase Timestamps

I store a list of users invited to an organisation, together with the timestamp denoting when the invite expires in Firebase. When I pull the timestamp from Firebase, I parse it to determine if it's still valid or has expired using:

Client Code

const inviteStatus = invitee?.validUntil.toDate() >= Date.now() ? 'valid_invitee' : 'expired_invitee'

I have also built in functionality to generate new invites via a call to Firebase Cloud Functions. Once an invite has been created, I return a new invitee object:

Firebase Functions Code

const expiryDate = admin.firestore.Timestamp.now().toDate()
expiryDate.setTime(expiryDate.getTime() + (1000 * 60 * 60 * 24 * 7)) // 7-day expiration

return {
    invitee: {
        validUntil: admin.firestore.Timestamp.fromDate(expiryDate)
    }
}

The reason I don't return just a Date object but instead convert it to Firestore's Timestamp format is to ensure that client always receives the validUntil data in the same format, regardless of whether it's read directly from Firestore DB or returned via Firebase Cloud Functions.

However, once this invitee object is returned and the client code runs (see first code snippet), I get the following error:

Uncaught TypeError: invitee.validUntil.toDate is not a function

Investigating

I have printed both objects (one directly pulled from DB and another returned via Cloud Functions) and noticed that the object returned directly from DB, when printed, shows a ut in Chrome Dev Tools next to the validUntil object, whereas the object returned from Cloud Functions does not display ut.

Printed Object Queried from Firestore enter image description here

Printed Object Returned from Cloud Functions enter image description here

Question

Why is Firebase generating two different types of timestamp objects where one can be converted to Date using .toDate() function and another throws an error?

Is there a way to return a proper timestamp object via Cloud Functions that I will be able to apply .toDate() function on in the client?

about 4 years ago · Juan Pablo Isaza
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