获取 "firebase.functions(app)" arg 需要一个 FirebaseApp 实例或在 React-Native Firebase 中未定义

Getting "firebase.functions(app)" arg expects a FirebaseApp instance or undefined in React-Native Firebase

我在 GoogleCloud 中触发了一个 httpscallable 函数,但收到了这个错误,我在文档中找不到它是什么:

"firebase.functions(app)" arg expects a FirebaseApp instance or undefined.

Ensure the arg provided is a Firebase app instance; or no args to use the default Firebase app.

这是我在 RN 应用程序中的代码:

   import { firebase } from '@react-native-firebase/functions'; 
   ...
    try {
        await firebase.functions('europe-west1').httpsCallable('createUserTest')();
    }
    catch (httpsError) {
        console.log(httpsError.message);
    }

还有我的云函数:

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

exports.createUserTest = functions.region('europe-west1').https.onCall(async (data, context) => {
    try {
        const callerUid = context.auth.uid;
        const callerUserRecord = await admin.auth().getUser(callerUid);
        return { result: callerUserRecord.customClaims };
    } catch (error) {
        return { error: error };
    }
});

我将此功能用于测试目的只是为了看看我是否可以收到当前用户的自定义声明,但是,它返回了该错误。

您似乎没有正确使用提供的客户端 API。我建议查看 documentation,尤其是示例 3。您需要这样做:

const defaultApp = firebase.app();
const functionsForRegion = defaultApp.functions('europe-west1');
await functionsForRegion.httpsCallable("createUserTest")()