I'm making an app with a login page, which I want it to retrieve a username of a user from a set of user data in realtime firebase, but when I run the code and sign in as an account it displays
JSON
Func Code:Snap (n9fd2UynzZT6rLXRs4puqYahWUk2) < null >
Code Block func checkIfUserSignedIn(){ if Auth.auth().currentUser?.uid == nil{ logout() }else{ let uid = Auth.auth().currentUser?.uid Database.database().reference().child("users").child(uid!).observeSingleEvent(of: .value, with: { (snapshot) in print(snapshot) }, withCancel: nil) } }
JSON
Code Block { "Test" : { "users" : { "guest" : { "email" : "guest@test.com", "name" : "guest", "uid" : "n9fd2UynzZT6rLXRs4puqYahWUk2" }, "guest2" : { "email" : "guest2@test.com", "name" : "guest2", "uid" : "r5WS623Cg7UL0UPSoq0S61sJj8Z2" } } }
What were you expecting ?
You get the first userId.
Is it what you request with observeSingleEvent ?
probably you have to change to observe.
If that works, don't forget to close the thread on this answer.
May read this:
https://stackoverflow.com/questions/46515454/swift-firebase-convert-observesingleevent-to-observe-childadded?rq=1
Note: that's more a Firebase question than a Swift.
So you should look in detail at Firebase API doc and possibly ask to Firebase forums directly.
You get the first userId.
Is it what you request with observeSingleEvent ?
probably you have to change to observe.
If that works, don't forget to close the thread on this answer.
May read this:
https://stackoverflow.com/questions/46515454/swift-firebase-convert-observesingleevent-to-observe-childadded?rq=1
Note: that's more a Firebase question than a Swift.
So you should look in detail at Firebase API doc and possibly ask to Firebase forums directly.