Javascript 如何使用Firebase的用户帐户将数据发送到数据库?

Javascript 如何使用Firebase的用户帐户将数据发送到数据库?,javascript,reactjs,firebase,firebase-realtime-database,firebase-authentication,Javascript,Reactjs,Firebase,Firebase Realtime Database,Firebase Authentication,我对Firebase有问题。 我知道如何使用Firebase framework创建电子邮件帐户,但不知道如何使用电子邮件帐户将数据发送到数据库 例如: 您发布了一条评论,其他用户希望看到 我已经看过Firebase文档,但它们没有说明如何使用帐户发送数据。 你有办法解决我的问题吗?提前谢谢。我不确定我是否理解正确。但是,如果您试图向其他用户发送消息,通常会得到一个模拟聊天室的数据库结构。对于1:1聊天室,我建议使用我在这里展示的结构: 在代码中,您可以向该房间添加一条消息,内容如下: let

我对Firebase有问题。 我知道如何使用Firebase framework创建电子邮件帐户,但不知道如何使用电子邮件帐户将数据发送到数据库

例如:

您发布了一条评论,其他用户希望看到

我已经看过Firebase文档,但它们没有说明如何使用帐户发送数据。
你有办法解决我的问题吗?提前谢谢。

我不确定我是否理解正确。但是,如果您试图向其他用户发送消息,通常会得到一个模拟聊天室的数据库结构。对于1:1聊天室,我建议使用我在这里展示的结构:

在代码中,您可以向该房间添加一条消息,内容如下:

let myUid = firebase.auth().currentUser.uid;
let otherUid = "uidOfTheOtherUser"; // This is a value you must 'know" somehow
let chatRoomId = 'chat_'+(myUid<otherUid ? myUid+'_'+otherUid : otherUid+'_'+myUid);

let roomRef = firebase.database().ref(chatRoomId);
roomRef.push({
  text: "This is my message",
  uid: myUid,
  timestamp: firebase.database.ServerValue.TIMESTAMP
});
让myUid=firebase.auth().currentUser.uid;
让otherUid=“uidOfTheOtherUser”//这是一个你必须“知道”的值
让聊天室ID='chat_u'+(myUid