Swift 尝试以google返回权限登录被拒绝

Swift 尝试以google返回权限登录被拒绝,swift,firebase,firebase-realtime-database,Swift,Firebase,Firebase Realtime Database,我的数据库有以下安全规则: { "rules": { "users": { "$uid": { ".write": "$uid === auth.uid" ".read": "$uid === auth.uid" } } } } 我还通过Firebase Auth实现了google登录。只要不启用这些规则,它就可以工作。 启用它们后,会出现以下错误: 拒绝发射前检查 我假设我试图在登录完成之前获取数据。您可以在下面

我的数据库有以下安全规则:

{
  "rules": {
    "users": {
      "$uid": {
        ".write": "$uid === auth.uid"
        ".read": "$uid === auth.uid"
      }
    }
  }
}
我还通过Firebase Auth实现了google登录。只要不启用这些规则,它就可以工作。
启用它们后,会出现以下错误:

拒绝发射前检查

我假设我试图在登录完成之前获取数据。您可以在下面找到代码。

我如何解决这个问题

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?) {
    if let error = error {
        print("Failed logging into Google: ", error)
        return
    }

    print("Successfully logged into Google.")

    guard let authentication = user.authentication else { return }
    let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken,
                                                   accessToken: authentication.accessToken)

    Auth.auth().signIn(with: credential) { (acc, error) in
        if let error = error {
            print("Failed to create User with Google: ", error)
            return
        }

        let databaseRef = Database.database().reference()
        guard let uid = Auth.auth().currentUser?.uid else { return }
        databaseRef.child("users").observeSingleEvent(of: .value, with: { (snapshot) in

            if snapshot.hasChild("\(uid)") {
                print("Data found.")
                let storyboard = UIStoryboard(name: "Main", bundle: nil)
                let vc = storyboard.instantiateViewController(withIdentifier: "ProfileViewController") as! ProfileViewController
                vc.readLeasing()
                vc.readData()
            } else {
                self.upDataToDatabase(from: user)
            }

        })

        let defaults = UserDefaults.standard

        defaults.set(user.profile.name, forKey: "name")

        logInViaGoogle = true
        defaults.set(logInViaGoogle, forKey: "logInViaGoogle")

        print("Successfully created user with Google.")
    }
}

你不能听取所有你需要的用户的意见

databaseRef.child("users/\(uid)").observeSingleEvent(of: .value, with: { (snapshot) in 
  if snapshot.exists() {
      print("Data found.")
      let storyboard = UIStoryboard(name: "Main", bundle: nil)
      let vc = storyboard.instantiateViewController(withIdentifier: "ProfileViewController") as! ProfileViewController
      vc.readLeasing()
      vc.readData()
  } else {
      self.upDataToDatabase(from: user)
  }         
})