Undefined UserId


Undefined UserId



enter image description here



So I am trying to do a 1v1 chat but the userid is showing up as undefined when I push up the message, and the other-other users id doesn't show.




if (user.emailVerified) {
userPic = user.photoURL;
userId = user.id;
displayName = user.displayName;

var pm = database.ref('chat/' + userId);


// Create a new message and add it to the list.
pm.push({
displayName: displayName,
userId: userId,
pic: userPic,
text: myString.toString(),
timestamp: new Date().getTime(), // unix timestamp in milliseconds
})
}



This is is the code I am using to push the message up



Edit



This is the userID I am talking about
enter image description here





you say Undefined UserId ... but there's only user.id or the global userId - so where is this UserId that is undefined - certainly not in your code - except of course it would be, but then so is ljhgwvliueghgl as that too isn't ever assigned a value
– Jaromanda X
Jun 30 at 7:14


Undefined UserId


user.id


userId


UserId


undefined


ljhgwvliueghgl





Are you sure that user object contains id?
– Kasabucki Alexandr
Jun 30 at 7:15





console.log(user) ... what do you see?
– Jaromanda X
Jun 30 at 7:15


console.log(user)





May be you need to access to userId like this user.userId instead user.id
– Kasabucki Alexandr
Jun 30 at 7:54





Can you try using database.ref().child('chat').child(userId) instead of database.ref('chat/' + userId )?
– André Kool
Jun 30 at 8:32


database.ref().child('chat').child(userId)


database.ref('chat/' + userId )









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

.

How to generate build files in next js

Delphi Android file open failure with API 26