Firebase for Mobile用户无法返回白名单

时间:2016-08-17 22:10:32

标签: android ios firebase firebase-realtime-database

我正在使用Firebase身份验证在iOS和Android上构建应用程序,而且我很难将其解决问题。这是我的功能,用于检查用户的UID是否在我的数据库中的白名单中。在viewDidLoad(_:)中调用此函数后,它将超过guard语句,然后退出函数而不进入完成块。

func checkUserAgainstDatabase(completion: (success: Bool) -> Void) {
    guard let currentUser = FIRAuth.auth()?.currentUser else { return }
    FirebaseController.ref.child("users").observeSingleEventOfType(.Value, withBlock: { (data) in

// This is where the function exits and the program continues running.

        let uid = data.childSnapshotForPath(currentUser.uid)
        if uid.exists() {
            completion(success: true)
        } else {
            completion(success: false)
            currentUser.deleteWithCompletion(nil)
        }
    })
}

以下是viewDidLoad(_:)中的电话:

UserController.shared.checkUserAgainstDatabase { (success) -> Void in
    if !success {
        self.showLoginSignUpView()
    }
}

以下是我对数据库的规定:

{
  "rules": {
    ".read": true,
    ".write": true
  }
}

提前致谢!

1 个答案:

答案 0 :(得分:0)

我花了一整天的时间发布这个试图做白名单解决方案并且无法让它发挥作用。然而,我的一个朋友给我发了一个类似于此的解决方案,它就像一个魅力。

END{for (f in min)print f,min[f],max[f]}