首页 文章

Firebase获取聊天消息的用户数据

提问于
浏览
0

我正在使用firebase email-password auth系统 . 登录后,用户可以发送消息,我将其存储为

{
    "uid":"14sr3424234234223456266",
    "date":"2016-12-02",
    "time":"23:29:55",
    "message": "hello friend"
}

我想在列表中显示聊天列表,如 displyName says: message ,但在我的消息对象中,我只有用户的uid . 如何通过uid从我的注册用户列表中显示用户displayName .

2 回答

  • 0

    您只能为当前已登录的用户检索用户信息(即姓名,电子邮件等)(在javascript中使用 firebase.auth().currentUser 对象) .

    如果要显示已创建该消息的用户的名称,我建议在消息对象本身中存储该用户的名称而不是uid .

    希望这可以帮助!!

  • 0

    如果您使用的是电子邮件密码系统,则必须将displayName存储为该用户的电子邮件,或者使用google登录系统,您可以正确访问显示名称 .

    {
    "displayName":firebase.auth().currentUser().displayName,
    "date":"2016-12-02",
    "time":"23:29:55",
    "message": "hello friend"
    }
    

    希望这种改变有所帮助!

相关问题