Firebase-functions: Date encoding httpsCallable

Created on 10 Sep 2018  路  5Comments  路  Source: firebase/firebase-functions

https.onCall triggers incorrectly encode Date objects as {}.

The docs say that anything JSON encodable should work. In standard implementations Date encodes to an ISO string e.g 2018-09-10T04:07:08.901Z. While this is a one way encoding I think it would be reasonable behaviour.

Version info

firebase-functions: master
firebase-tools: N/A

firebase-admin: N/A

Test case

export const listener = functions.https.onCall(async (data, context) => {
  return { date: new Date() };
}

Steps to reproduce

Were you able to successfully deploy your functions?

Yes

Expected behavior


Date is encoded as an ISO string, timestamp or using a custom Date encoding.

Actual behavior

Date is encoded as {}

documentation

All 5 comments

@bklimt Would you mind taking a look?

Hi. Thank you for this feedback. It seems the documentation could be clearer. Dates are not yet supported at this time. We are investigating the right way to support them, and may add support in the future. For now, I'd recommend encoding them as strings or numbers yourself as a workaround.

Is a better default behaviour possible than sending an empty object?
At the moment if (res.date) { /*...*/ } executes which gets around some high level checks.

Or could you potentially add a warning when the function executes?

Edit: Noticed the reference has more extensive documentation.

I think, this issue should be closed.

Why don't you fix this with just if _.isDate(data) { return data.toJSON() } as proposed here https://stackoverflow.com/questions/53520674/returning-dates-server-timestamps-in-cloud-callable-functions ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

malikasinger1 picture malikasinger1  路  50Comments

FredyC picture FredyC  路  39Comments

agordeev picture agordeev  路  43Comments

ahaverty picture ahaverty  路  27Comments

iouhammi picture iouhammi  路  24Comments