question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Date encoding httpsCallable

See original GitHub issue

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 {}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

19reactions
soyanakagawacommented, Dec 1, 2018

I think, this issue should be closed.

1reaction
dobromyslovcommented, Nov 27, 2020

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 ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

iOS Support for Date type for functions.httpsCallable
Firestore APIs work nice to encode Date types on iOS and Swift when working with documents. Cloud functions are great but the lack...
Read more >
What should I return in an https callable function if it doesn't ...
The firebase-functions SDK automatically encodes the value returned by the user into this JSON format. The client SDKs automatically decode ...
Read more >
HttpsCallable | JavaScript SDK | Node.js (client) API reference
Reference for HttpsCallable.
Read more >
How to decode a TimeStamp from the firebase Firestore in ...
The first thing was to 'set' my date on the server-side by using timeStamp's 'toString()' - even though it looks like a string...
Read more >
Timestamp - React Native Firebase
It is encoded using the Proleptic Gregorian Calendar which extends the Gregorian calendar backwards to ... Convert a Timestamp to a JavaScript Date...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found