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

192
Visualizações
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 à 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