Calling Firebase function from react-native app: [Unhandled promise rejection: Error: Response is not valid JSON object.]

Viewed 74

I try to run a firebase function from a react-native application.

In it's simplest form it should just take a value and return it again to the application with the uid of the logged in user.

The firebase function looks as follows:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();

exports.bfs = functions.region("europe-west1").https.onCall((data, context) => {
    const steps = data.steps;
    const uid = context.auth.uid;
    const obj = {steps:steps, uid:uid};
    return JSON.stringify(obj);
});

Of course it has been deployed with firebase deploy --only functions:bfs

In the react-native App the following is executed:

import "firebase/functions";
import firebase from "firebase";

firebase.initializeApp(firebaseConfig);

var bfs = firebase.functions().httpsCallable("bfs");
bfs({ steps: 1 }).then((result) => console.log(result));

But no matter how I return the value in the firebase function (tried a lot of different things) there is always the same error message:

[Unhandled promise rejection: Error: Response is not valid JSON object.]
at node_modules\qrcode\lib\core\segments.js:2:18 in <global>
at node_modules\qrcode\lib\renderer\canvas.js:35:33 in render
at node_modules\tslib\tslib.js:77:12 in <anonymous>
at http://192.168.2.100:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&minify=false:160200:21 in <unknown>
at http://192.168.2.100:19000/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&minify=false:160154:31 in fulfilled
at node_modules\react-native\node_modules\promise\setimmediate\core.js:37:13 in tryCallOne
at node_modules\react-native\node_modules\promise\setimmediate\core.js:123:24 in setImmediate$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:181:14 in _callImmediatesPass
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:441:30 in callImmediates
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:387:6 in __callImmediates
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:135:6 in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:134:4 in flushedQueue

I tried it with return {steps:steps, uid:uid} or return '{"steps":${steps}, "uid":${uid}}' but nothing seems to work.

0 Answers
Related