【问题标题】:Flutter app giving UNAUTHENTICATED errors when calling Firebase cloud functions directlyFlutter 应用程序在直接调用 Firebase 云函数时出现 UNAUTHENTICATED 错误
【发布时间】:2020-07-17 18:56:06
【问题描述】:

我尝试直接从我的 FLUTTER 应用程序中使用 firebase 云函数 oncall 方法,即使我已登录,它也会不断给我一个 UNAUTHENTICATED 错误 Flutter 应用代码

CloudFunctions function = CloudFunctions.instance;
final HttpsCallable createCallable = function.getHttpsCallable(functionName: 'two_create')
  ..timeout = const Duration(seconds: 30);

try {
  final HttpsCallableResult result = await createCallable.call({
    'stay': 'con50',
    'open': false
  });

  print(result.data);
}on CloudFunctionsException catch(e){
  print('-----------------------------------------------');
  print(e.code); print(e.message); print(e.details);
  print('-----------------------------------------------');
}

dynamic user = await FirebaseAuth.instance.currentUser();
print(user.uid);

我收到了这个错误

I/flutter (19466): -----------------------------------------------
I/flutter (19466): UNAUTHENTICATED
I/flutter (19466): UNAUTHENTICATED
I/flutter (19466): null
I/flutter (19466): -----------------------------------------------
I/flutter (19466): eMTX6OcYPOSeYdimmCSqjbnnmWM2

我尝试打印出 uid 以显示我当前已登录并且我当前正在使用 android 设备进行测试。

这是我从我的应用程序调用的函数

exports.two_create = functions.https.onCall(async (context,data)=>{
    var oncall = require('./httponcall');

    var text = await oncall.create(admin,allRef.one2,context,data);
    return text;
})

当 Firebase 控制台被触发时,我没有得到任何日志

【问题讨论】:

  • 请编辑问题以显示您尝试调用的函数代码,以及它可能生成的任何日志。
  • 如果该函数实际上并未被调用(您找不到任何日志),请联系 Firebase 支持以寻求帮助。 support.google.com/firebase/contact/support
  • 这可能是 Node 版本的问题。请看:stackoverflow.com/questions/56120115/…
  • 我也有同样的问题!
  • 我尝试更改节点版本我仍然得到同样的错误

标签: android firebase flutter google-cloud-functions


【解决方案1】:
  1. 首先将 Firebase 工具和依赖项更新到最新版本。

https://firebase.google.com/docs/functions/get-started?authuser=0#set-up-node.js-and-the-firebase-cli

npm install firebase-functions@latest firebase-admin@latest --save

npm install -g firebase-tools

  1. 部署后

  2. 转到 Google 云控制台 (GCP) 而不是 Firebase 控制台 GCP 侧边栏 > 云函数 > 选择您的函数 转到权限 > 添加 > “allUsers” > Firebase > Firebase 查看器

这样做需要您自担风险,我不是任何云开发者。我不知道像这样添加 allUsers 的风险 我是 Flutter 开发的新手

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-03
    • 1970-01-01
    • 2023-02-20
    • 2021-08-29
    • 2019-08-12
    • 2019-07-29
    • 2019-11-23
    • 2021-07-16
    相关资源
    最近更新 更多