1

I am trying to create a web application with ReactJs and firebase. I want to know how to create three users with different roles like doctor, patient, pharmacist.

My Signup.js file

    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"
    })
1

1 Answer 1

1

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:

const ref = db.collection("patient")

Sign up to request clarification or add additional context in comments.

3 Comments

i have done that i have currently made 3 signups and 3 login forms but i want only one login.This signup.js is for doctor i have two more signup.js .For patient it is db.collection("patient") and for pharmcist its db.collection("pharmacist").I want to know if there is a firebase function which will allow me to give roles so that when the user logs in i can just have one login form with the authenticate function and route them to the homepage using their roles
const handleLogin = useCallback( async event => { event.preventDefault(); const { email, pass } = event.target.elements; try { await app .auth() .signInWithEmailAndPassword(email.value, pass.value); hist.push(Routes.PatientDashboardOverview.path); } catch (error) { alert(error); } }, [history] );
Then you need to pass the user type into the handleLogin arguments: const handleLogin = (type) => { event.preventDefault(); const { email, pass } = event.target.elements; .....} and call handleLogin with the selected user type as a string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.