【问题标题】:Firebase + Flutter - Cloud functions onCall result in "unauthenticated" error from Android appFirebase + Flutter - 云函数 onCall 导致 Android 应用出现“未经身份验证”错误
【发布时间】:2019-09-30 20:56:34
【问题描述】:

我已将以下测试 https.onCall 函数部署到 firebase 上的 Cloud Functions - 使用节点 10 部署:

export const helloWorld = functions.https.onCall((data, context) => {

    return {
        "message": "Hello, world",
    }

}); 

从节点环境测试时,此函数按预期返回。

但是,在我的颤振 (android) 应用程序中 - 使用 Cloud functions plugin for Flutter,我收到以下身份验证错误,尽管已登录(通过电话号码身份验证):

颤振代码:

void _checkAuth() async { 

    print("Check auth");
    final FirebaseAuth _auth = FirebaseAuth.instance;
    var user = await _auth.currentUser();

    print(user.toString());

    _testFunCall();
}

void _testFunCall() async {
    HttpsCallable callable = CloudFunctions.instance
        .getHttpsCallable(functionName: 'helloWorld');

    try {
        final HttpsCallableResult result = await callable.call();
        print(result.data);

    } on CloudFunctionsException catch (e) {
        print('caught firebase functions exception');
        print(e.code);
        print(e.message);
        print(e.details);
    } catch (e) {
        print('caught generic exception');
        print(e);
    }
}

错误:

I/flutter ( 4662): caught firebase functions exception
I/flutter ( 4662): UNAUTHENTICATED
I/flutter ( 4662): Unauthenticated
I/flutter ( 4662): null

有什么想法吗?

【问题讨论】:

  • 在用户使用 firebase 登录后调用这个 _checkAuth() 方法。那么只有你可以得到 _auth.currentUser();否则用户将为零且仅未经身份验证。
  • 我在 2020 年 4 月的最新插件中遇到了这个确切的错误,还有其他人吗?
  • 这里也一样。你找到解决办法了吗?
  • 这也发生在我的团队身上。我们使用节点 12。这仍然是一件事吗?
  • “节点”中的相同问题:“14”

标签: android firebase flutter google-cloud-functions


【解决方案1】:

问题在于部署到云功能时使用 Node 10。

节点 10 目前处于测试阶段。切换到节点 8,它工作正常:

在您的云函数目录中的package.json 中,切换:

  "engines": {
    "node": "10"
  },

到:

  "engines": {
    "node": "8"
  },

【讨论】:

  • 想必他们会在这里更新 beta 的状态——node 8 是目前唯一推荐的引擎:firebase.google.com/docs/functions/…
  • 不幸的是,即使使用节点 8 也会出现此问题
  • 嘿@AndreyGordeev,你能找到解决这个问题的方法
猜你喜欢
  • 2021-12-05
  • 2022-01-03
  • 2020-11-24
  • 2023-02-04
  • 2018-05-02
  • 2020-10-06
  • 2017-02-13
  • 1970-01-01
  • 2021-03-16
相关资源
最近更新 更多