0

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.

3
  • 1
    "auth != null" means that you need to be authenticated. you can use "true" instead to allow anonymous read/write, but be cautious because this means any user with any client applications can modify your firebase data. Commented May 24, 2018 at 15:14
  • @GünterZöchbauer So what is the point of "Anonymous Authentication" ? Commented May 24, 2018 at 15:17
  • Allowing anybody (even anonymous) to read is fine for non-sensitive data. Also allowing anonymous to write values of a certain structure to a certain path might make sense. Just allowing anonymous to allow write without restriction is hazardous to your app and probably also to your finances if you're unlucky and someone misuses your database with high volume data. Commented May 24, 2018 at 15:26

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.