0

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

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();
                        }
                    }
                });

    }

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

4

1 回答 1

1

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

试试这个:

return admin.auth()
    .createCustomToken(...)
    .then(...)
    .catch(...)
于 2020-06-26T16:27:41.207 回答