Vah.Sah Vah.Sah - 1 year ago 258
Swift Question

Firebase reading returns null

In my app I'm trying to get user information from Firebase database, but it always returns null. Here is my code for reading current user information from database

func workWithDataBase(){
let email = ""
let password = "test23"

FIRAuth.auth()?.signIn(withEmail: email, password: password, completion: { (user, error) in
if error != nil {
} else {
print("SIGNED IN\n")

let uid = FIRAuth.auth()?.currentUser?.uid

FIRDatabase.database().reference().child("users").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in
}) {
(error) in

and here is the output and the screenshot of Firebase database
enter image description here

enter image description here

My question is if the fields for email and name are not empty why "observeSingleEvent" method returns null? How can I fix this?

Answer Source

Try This:-

 FIRDatabase.database().reference().child("user").child(FIRAuth.auth()!.currentUser!.uid).observeSingleEvent(of: .value, with: { (snapshot) in
        }) {(error) in
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download