【问题标题】:How to get data returned from Cloud Functions on Android如何在 Android 上获取从 Cloud Functions 返回的数据
【发布时间】:2020-10-17 07:18:14
【问题描述】:

我正在尝试使用云功能使用自定义令牌对用户进行身份验证。生成令牌的代码是:

export const test = functions.https.onCall(() => {
     const uid = 'test_uid'
     admin.auth().createCustomToken(uid)
     .then((customtoken) => {
         console.log(customtoken)
         return customtoken
     }).catch((error) => {
         console.log(error)
     })
 })

客户端的代码是:

private void getmessage() {
        FirebaseFunctions.getInstance()
                .getHttpsCallable("test")
                .call()
                .addOnCompleteListener(this, new OnCompleteListener<HttpsCallableResult>() {
                    @Override
                    public void onComplete(@NonNull Task<HttpsCallableResult> task) {
                        if(task.isSuccessful()){
                            Toast.makeText(getApplicationContext(), task.getResult().getData().toString(), Toast.LENGTH_LONG).show();
                        }else{
                            Toast.makeText(getApplicationContext(), "Task is NOT Successful", Toast.LENGTH_LONG).show();
                        }
                    }
                });

    }

令牌成功登录到控制台,但在客户端返回空值。有什么我做错了吗?

【问题讨论】:

    标签: android firebase firebase-authentication google-cloud-functions


    【解决方案1】:

    可调用函数需要返回一个在异步工作完成时解析的 Promise。该承诺应该通过发送给客户端的数据来解决。现在,您的函数没有返回任何内容。

    试试这个:

    return admin.auth()
        .createCustomToken(...)
        .then(...)
        .catch(...)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-17
      • 2018-12-22
      • 2021-12-02
      • 1970-01-01
      • 1970-01-01
      • 2021-07-25
      • 2019-09-25
      • 1970-01-01
      相关资源
      最近更新 更多