Swift: Firebase Read Permission Denied

So, I am creating this fast application that has data that must be read before a user logs in.

To protect it from reading from my application, I set a basic security rule:

".read": "auth != null" 

To prevent reading before entering the system, I installed the download view controller on call:

 func application(application: UIApplication, willFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool { let ref = Firebase(url: "<my firebase url>") ref.observeAuthEventWithBlock({ authData in if authData != nil { segueToListViewController() } }) return true } 

But when I get to this point, sometimes firebase gives me the error "allowed rejection", sometimes it is not.

I am sure that the registered user, because I register everything:

  • Login changed
  • User logged in to AuthData facebook:
  • applicationDidBecomeActive
  • Loaded ListViewController
  • Data loading
  • Error: Domain Error = com.firebase Code = 1 "Permission denied"

So, why does Firebase sometimes refuse to read when a user logs in?

+4
source share
1 answer

I'm very late to this party, but it can help if you put the .read rule one level up, directly under the child name.

for instance

 { "rules": { "users": { "$uid": { ".read": "auth != null && auth.uid == $uid", ".write": "auth != null && auth.uid == $uid" } }, "child": { ".read": "auth != null", ".write": "auth != null", "$child": { } } } } 
+2
source

All Articles