How to save, with anonymous authentication, to Firebase database - using Flutter

梦想的初衷 提交于 2019-12-24 23:16:08

问题


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: }]})

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.


回答1:


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.



来源:https://stackoverflow.com/questions/50512727/how-to-save-with-anonymous-authentication-to-firebase-database-using-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!