Date encoding httpsCallable
See original GitHub issuehttps.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:
- Created 5 years ago
- Reactions:6
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 ?