Reputation: 73
let userID = Auth.auth().currentUser?.uid
ref.child("players").child(userID!).observeSingleEvent(of: .value, with: { (snapshot) in
let value = snapshot.value as! NSDictionary
print("DICT VALUE",value)
})
I'm trying to get the profile of my signed in user. My issue is that if is use the variable userID
let userID = Auth.auth().currentUser?.uid
the snapshot is null. Returns this Snap (feoMdSquBSMHFXcPhZKbpsIGlKe2) <null>
if I use the literal string let userID = "feomdsqubsmhfxcphzkbpsiglke2"
for the userID child I get the expected return
Snap (feomdsqubsmhfxcphzkbpsiglke2) {
currentSelected = 0;
email = "[email protected]";
uid = feoMdSquBSMHFXcPhZKbpsIGlKe2;
username = "player 2";
}
I can confirm the userID is valid
let userID = Auth.auth().currentUser?.uid
print(userID!)
returns feoMdSquBSMHFXcPhZKbpsIGlKe2
here is the data that is stored
{
"players" : {
"feomdsqubsmhfxcphzkbpsiglke2" : {
"currentSelected" : false,
"email" : "[email protected]",
"uid" : "feoMdSquBSMHFXcPhZKbpsIGlKe2",
"username" : "player 2"
},
"o4azcazrxjqc3toybykk0ghbd9o2" : {
"currentSelected" : false,
"email" : "[email protected]",
"uid" : "O4aZCAZrXJQc3TOYbykK0ghbD9O2",
"username" : "player 1"
}
}
}
Upvotes: 0
Views: 367
Reputation: 40
If I remember correctly, Firebase Database keys are case sensitive. In your database, your userID is:
feomdsqubsmhfxcphzkbpsiglke2
However, the actual userID of whatever user you are signed in as is:
feoMdSquBSMHFXcPhZKbpsIGlKe2
Try this:
let userID = feoMdSquBSMHFXcPhZKbpsIGlKe2
ref.child("players").child(userID!).observeSingleEvent(of: .value, with: { (snapshot) in
let value = snapshot.value as! NSDictionary
print("DICT VALUE",value)
})
and see what it gives you. If it doesn't work, you know that you have to watch the case of all your characters.
Upvotes: 2