Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

90
Views
getting an error while trying to run my app with firestore: Attempted to assign to readonly property

I'm currently working on an app in which you can keep track of Root Canal patients and it was working fine for a long time...but after the new update of the firebase package in expo...I've been getting an error while trying to sign up. It says "Attempted to assign to readonly property" but my cloud firestore rules are set so that it is allowed. So, I am not too sure about what I did wrong.

This is the firestore rules:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if
          request.time < timestamp.date(2023, 12, 31);
    }
  }
}

This is the code for the sign up function:

onSignUp = async (email, password) => {
    firebase // used import * as firebase from 'firebase/auth'
      .createUserWithEmailAndPassword(
        this.state.modalEmail,
        this.state.modalPassword
      )
      .then(() => {
        firestore // used import * as firestore from 'firebase/firestore'
          .collection("Users")
          .doc(this.state.modalEmail)
          .set({
            username: this.state.username,
            email_id: this.state.modalEmail,
            clinicName: this.state.clinicName,
            age: this.state.age,
            phoneNumber: this.state.phoneNumber,
            tablets: []
          });
        this.setState({ isModalVisible: false });
        this.props.navigation.replace("Home");
      })
      .catch((error) => {
        Alert.alert("Coudn't create user", error.message);
        console.log(error)
      });
  };

the error I'm getting:

enter image description here

If you have any idea on what I did wrong or what I could do to fix this issue please let me know. Thanks in advance!

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

If your using firebase 9, the signature is changed. the auth object needs to be passed as first parameter.

const auth = getAuth();
createUserWithEmailAndPassword(auth, email, password)

https://firebase.google.com/docs/auth/web/password-auth

7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs