0

iOS client calls function with the following params:

func buyTicket(contestId: String, points: Int) -> SignalProducer<Void, Error> {
    Functions.functions().httpsCallable("myFunction").call([
        "userId": Auth.auth().currentUser!.uid,
        "points": points,
        "contestId": contestId
        
    ], completion: ...

Then at the beginning of the function I have this log

const userId = req.body.data.userId;
const contestId = req.body.data.contestId;
const points = req.body.data.points;

console.log(`myFunction called with userId: ${userId} contestId: ${contestId} points: ${points}`);

What gets printed is

myFunction called with userId: BzoW5pWLbWRnd2UgjnTkfd3xfNf2 contestId: pBsQo0FHMyu4ay18dexy points: [object Object]

why is points converted to an object? This is causing my function to crash when I try to pass points to FieldValue.increment

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
aryaxt
  • 76,198
  • 92
  • 293
  • 442
  • Instead of interpolating `points` into a string format, log points like this, to see a better string representation: `console.log(points)` – Doug Stevenson Jul 11 '20 at 21:15
  • Also, please edit the question to show the entire cloud function. It looks like you might be doing something else very wrong. – Doug Stevenson Jul 11 '20 at 21:17

1 Answers1

1

It looks like you're mixing a HTTP Cloud Function implementation with an invocation of a Callable Cloud Function. The two types of functions are not the same, and not compatible.

To invoke a HTTP function from your app, you'll perform a regular HTTP request from your Swift code. So for example with How do I make an HTTP request in Swift?

If you want to keep your Swift code the same, you'll have to implement your server-side as a Callable Cloud Function. This means the declaration looks like:

exports.myFunction = functions.https.onCall((data, context) => {
  ...
});

And you get the parameters as data.userId, data.points, etc.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807