如何使用匿名身份验证将文件保存到Firebase数据库-使用Flutter [英] How to save, with anonymous authentication, to Firebase database - using Flutter

本文介绍了如何使用匿名身份验证将文件保存到Firebase数据库-使用Flutter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过匿名身份验证进行身份验证后,我的权限被拒绝了

I'm getting permission denied after I have authenticated with Anonymous Auth

[ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (21033): PlatformException(-3, Permission denied, )
...
_getCurrentUser: FirebaseUser({providerId: firebase, uid: DOIL...............u54j1, displayName: , email: , isAnonymous: true, isEmailVerified: false, providerData: [{providerId: firebase, uid: DOIL//////////////54j1, displayName: , email: }]})

我在Firebase数据库上的规则是

My rules on the Firebase DB are

{
  "rules": {
    //Test rule
//     "users": {
//   "$uid": {
//     ".read": "auth != null && auth.uid == $uid",
//     ".write": "auth != null && auth.uid == $uid",
//       }
//    }

//       General rule - closed to everyone but app uses
         ".read": "auth != null",
         ".write": "auth != null"
  }
}

我用来保存数据的代码-与设置为向所有人开放的数据库规则一起正常工作.

The code I use to save data - works fine with DB rules set to open to all.

      _saveUserData(UserEntry userData) async {

    print("_saveUserData jsonData =" userData.toJson().toString());

    // SAVE MY DATA TO DB
    // tUsers = db reference to the child node users on Firebase
    _tUsers.push().set(talentUserData.toJson());


  }

我在做什么错?任何帮助表示赞赏.谢谢.

What am I doing wrong ? Any assistance is appreciated. Thanks.

推荐答案

是希望为某人省去一些麻烦.我发现问题出在没有新的Firebase数据库实例.我在main.dart中创建了实例,并将其传递给构造函数中的HomePage(根据库中的示例文件).

In the hope of saving someone a headache. I found the problem to be not getting a fresh instance of the Firebase Database. I created the instance in my main.dart and passed it to my HomePage in the constructor (per the example file in the library).

当我得到一个新实例时,经过了无奈的调试……它起作用了.现在,我可以进行匿名登录,以便只有安装了该应用程序的用户才能写入数据库.

When I got a fresh instance ...out of desperation debugging...it worked. I can now have anonymous login so that only people who have installed the app can write to the database.

这篇关于如何使用匿名身份验证将文件保存到Firebase数据库-使用Flutter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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