My goal is to retrieve a date from a firebase function:
import * as functions from 'firebase-functions';
const date = functions.https.onCall(() => {
return {
date: new Date(),
iso: new Date().toISOString()
};
});
export default date;
However, when I check the result using firebase functions:shell, this is what I see:
RESPONSE RECEIVED FROM FUNCTION: 200, {
"result": {
"date": {},
"iso": "2018-12-08T18:00:20.794Z"
}
}
It seems like the Date() object is being serialized incorrectly as an empty object. Shouldn't there be at least a .toString() or some transformation of the Date instance?
So, does this mean that I should avoid returning Date instances altogether? Do I need to create a custom serializer to convert Date instances to strings using methods like .toISODate()? It feels like I must be overlooking something!
Thank you.