简体   繁体   English

如何使用 reactjs 和 firebase 创建不同的用户

[英]how to create different users using reactjs and firebase

I am trying to create a web application with ReactJs and firebase.我正在尝试使用 ReactJs 和 firebase 创建 web 应用程序。 I want to know how to create three users with different roles like doctor, patient, pharmacist.我想知道如何创建三个具有不同角色的用户,例如医生、患者、药剂师。

My Signup.js file我的 Signup.js 文件

    if (pass.value != cpass.value) {
  alert("Password dont match")
}
else {
  try {
    var e = email.value
    const ref = db.collection("doctor")
    setLoading(true)
    await app
      .auth()
      .createUserWithEmailAndPassword(email.value, pass.value);
    ref.doc(e).set({
      "name": uname.value,
      "dob": dob.value,
      "email": email.value,
      "phno": phno.value,
      "regno": regno.value,
      "regyear": regyear.value,
      "gender": gender.value,
      "addr": addr.value,
      "pincode": pin.value,
      "city": city.value,
      "state": state.value,
      "bloodtype": bloodtype.value,
      "speciality": speciality.value,


    }).then(() => {
      console.log("Document successfully written!");
    });
    db.collection("users").doc(email.value).set({
      "email":email.value,
      "userType":"doctor"
    })

You have set the collection to doctors in the following code snippet:您已在以下代码段中将集合设置为医生:

const ref = db.collection("doctor")

If you want to add a different user to a different firebase collection you just need to replace the collection name:如果您想将不同的用户添加到不同的 firebase 集合中,您只需替换集合名称:

const ref = db.collection("patient")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM