Firebase + Flutter-云功能onCall导致“未经身份验证"来自Android应用的错误 [英] Firebase + Flutter - Cloud functions onCall result in "unauthenticated" error from Android app

查看:52
本文介绍了Firebase + Flutter-云功能onCall导致“未经身份验证"来自Android应用的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have deployed the following test https.onCall function to Cloud Functions on firebase - deployed using node 10:

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

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

}); 

从节点环境进行测试时,此函数将按预期返回.

This function returns as expected when tested from a node environment.

但是,在我的flutter(android)应用程序中-使用云函数插件对于Flutter ,尽管已登录(通过电话号码auth),但仍收到以下身份验证错误:

However, within my flutter (android) app - using the Cloud functions plugin for Flutter, I'm getting the following authentication error, despite being logged in (via phone number auth):

颤振代码:

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

有什么想法吗?

推荐答案

问题是在部署到云功能时使用了Node 10.

The problem was using Node 10 when deploying to cloud functions.

节点10当前处于beta中.切换到节点8,它可以正常工作:

Node 10 is currently in beta. Switched down to node 8 and it works fine:

在云功能目录的package.json中,切换:

In package.json in your cloud functions dir, switch:

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

收件人:

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

这篇关于Firebase + Flutter-云功能onCall导致“未经身份验证"来自Android应用的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆