0
votes

The behavior for Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK. To hide this warning and ensure your app does not break, you need to add the following code to your app before calling any other Cloud Firestore methods:

const firestore = new Firestore();
const settings = {/* your settings... */ timestampsInSnapshots: true};
firestore.settings(settings);

With this change, timestamps stored in Cloud Firestore will be read back as Firebase Timestamp objects instead of as system Date objects. So you will also need to update code expecting a Date to instead expect a Timestamp. For example:

// Old:
const date = snapshot.get('created_at');
// New:
const timestamp = snapshot.get('created_at');
const date = timestamp.toDate();

Please audit all existing usages of Date when you enable the new behavior. In a future release, the behavior will change to the new behavior, so if you do not follow these steps, YOUR APP MAY BREAK.

This is my firestore Functions code


const functions = require('firebase-functions');
const { firestore } = require('../admin');
const admin = require("firebase-admin");



/**
 * Cloud Function: Handle device state updates
 */
module.exports = functions.pubsub.topic('telemetry-topic').onPublish(async (message) => {
  const deviceId = message.attributes.deviceId;
  // Write the device state into firestore
const deviceRef = firestore.doc(`devices/${deviceId}`);
  const deviceTimeRef = firestore.doc(`time/${deviceId}`);
  const deviceupdateTimeRef = firestore.doc(`updatecurrenttime/${deviceId}`);

  var key = new Date().toLocaleDateString()
  var person = {[key]:message.json};
  var key1 = new Date(admin.firestore.Timestamp.now().seconds*1000).toLocaleDateString()
  var person1 = {[key1]: admin.firestore.FieldValue.serverTimestamp()}
  
  try {
   
    // Ensure the device is also marked as 'online' when state is updated
   await deviceTimeRef.update(person);
   await deviceupdateTimeRef.update(person1);
    console.log(`State updated for ${deviceId}`);
  } catch (error) {
    console.error(`${deviceId} not yet registered to a user`, error);
  }
  
  
});


1

1 Answers

0
votes

It sounds like you're using a very old version of the Firebase Admin SDK. Just update it to the latest.

npm install firebase-admin@latest

Either that, or simply follow the instructions in the error message.