FirebaseError: Function Query.where() called with invalid data. Unsupported field value: undefined

Viewed 1627

I want to get only the document specified by where.

Store the email address registered in the uid property as a value in the Firestore at the time of new registration.

    async signUp() {
      const db = firebase.firestore();
      await this.$store.dispatch('signUp', { username:this.username, email:this.email, password:this.password });
      await db.collection('myData').doc(this.username).set({
        uid: this.email,
        email: this.email,
        myWallet: 1000
      });
      this.$router.push('/home');
    }
async signUp({ commit }, userInfomation) {
      try {
        await firebase
          .auth()
          .createUserWithEmailAndPassword(
            userInfomation.email,
            userInfomation.password
          );
        const user = firebase.auth().currentUser;
        await user.updateProfile({
          displayName: userInfomation.username,
        });
        commit('setUserName', user);
      } catch (e) {
        alert(e.message);
      }
    },
  mutations: {
    setUserName(state, user) {
      state.userName = user.displayName;
    },
actions: {
async getMyWallet({ commit, state }) {
      const uid = state.updateUserName.email; //Information on the logged-in user is stored in updateUserName.
      const db = firebase.firestore();
      const doc = await db
        .collection('myData')
        .where('uid', '==', uid)
        .get();
      commit('getMyWallet', doc);
    }
}

When I ran it, I got the error written in the title.

Is it written incorrectly?

Is there any other good way?

    async getMyWallet({ commit }) {
      firebase.auth().onAuthStateChanged(user => {
        const uid = user.email;
        const db = firebase.firestore();
        const doc = db
          .collection('myData')
          .where('uid', '==', uid)
          .get();
        commit('getMyWallet', doc);
      });
    },

When I rewrote the getMyWallet part, I got a new error.

Error details: doc.data is not a function

0 Answers
Related