首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当触发云函数时在RN应用程序中接收[错误:内部]

当触发云函数时在RN应用程序中接收[错误:内部]
EN

Stack Overflow用户
提问于 2020-04-22 20:44:55
回答 1查看 402关注 0票数 0

我有一个Google函数,我从我的RN应用程序中调用它,但它正在返回

错误:内部

我已经将权限设置为未通过身份验证的用户,因此任何人都可以调用它--仅用于测试目的。当我设置为经过身份验证的用户权限时,它会引发另一个错误:即使我是经过身份验证的,并且可以在我的应用程序中获得currentUser id,但它仍然会引发另一个错误。

尝试搜索这个错误,但它没有送我到任何可能的解决方案,所以决定在这里张贴,并希望收到的答复,将帮助我解决它。

代码语言:javascript
运行
复制
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

exports.createUser = functions.region('europe-west1').https.onCall(async (data, context) => {

try {

    //Checking that the user calling the Cloud Function is authenticated
    if (!context.auth) {
        throw new UnauthenticatedError('The user is not authenticated. Only authenticated Admin users can create new users.');
    }

    const newUser = {
        email: data.email,
        emailVerified: false,
        password: data.password,
        disabled: false
    }
    const role = data.role;
    const userRecord = await admin
        .auth()
        .createUser(newUser);
    const userId = userRecord.uid;
    const claims = {};
    claims[role] = true;
    await admin.auth().setCustomUserClaims(userId, claims);
    return { result: 'The new user has been successfully created.' };
} catch (error) {
    if (error.type === 'UnauthenticatedError') {
        throw new functions.https.HttpsError('unauthenticated', error.message);
    } else if (error.type === 'NotAnAdminError' || error.type === 'InvalidRoleError') {
        throw new functions.https.HttpsError('failed-precondition', error.message);
    } else {
        throw new functions.https.HttpsError('internal', error.message);
    }
}
});

在我的RN应用程序中,我这样称呼它:

代码语言:javascript
运行
复制
    var user = {
                role: role
               }

    const defaultApp = firebase.app();
    const functionsForRegion = defaultApp.functions('europe-west1');
    const createUser = await functionsForRegion.httpsCallable('createUser');
    createUser(user)
            .then((resp) => {
                //Display success
             });
                console.log(resp.data.result);
            })
            .catch((error) => {
                console.log("Error on register patient: ", error)
            });

我认为我在RN应用程序中调用它的方式是正确的,因为我已经用testFunction测试了它,并返回了一个简单的字符串。所以,我认为问题就在函数本身的某个地方。

编辑:,我只是通过简单地调用函数并返回上下文来测试,它总是返回内部错误:

代码语言:javascript
运行
复制
exports.registerNewPatient = functions.region('europe-west3').https.onCall((data, context) => {
 return context; //this is returned as INTERNAL error. 
}

我只是无法理解这里发生了什么,为什么当我作为一个用户进行身份验证并且应该返回经过身份验证的用户数据时,它会返回内部错误,对吗?

EN

回答 1

Stack Overflow用户

发布于 2020-04-23 00:27:43

在您的console.log(context) ; console.log(data)函数中尝试一些registerNewPatient语句,并查看日志。他们怎么说?

需要考虑的其他事情可能包括在客户端代码中使用europe-west1,而函数代码有europe-west3。试着把这些排成一列,看看它是否有效?根据我的经验,如果不存在指定的函数,客户端将收到一个内部错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61374792

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档