react-native-firebase-chat-core icon indicating copy to clipboard operation
react-native-firebase-chat-core copied to clipboard

React Native createUserInFirestore => Error: Unsupported field value: undefined

Open milch-shake opened this issue 1 year ago • 5 comments

While running createUserInFirestore with minimum setup given from https://docs.flyer.chat/react-native/firebase/firebase-usage { firstName: 'John', id: credential.user.uid, // UID from Firebase Authentication imageUrl: 'https://i.pravatar.cc/300', lastName: 'Doe', }

getting Error: Error: Unsupported field value: undefined

while setting all data: { firstName: userData?.fullname, id: UID, imageUrl: userData?.imagePath, lastName: ' ', metadata: ' ', lastSeen: firebaseCurrentUser?.metadata?.lastSignInTime, role : userRole }

the await will never ends and i didn't get response.

milch-shake avatar May 22 '23 10:05 milch-shake

I'm also Facing the same issue is it resolved? @milch-shake

DeeAndroid avatar Aug 15 '23 04:08 DeeAndroid

I'm also Facing the same issue is it resolved? @milch-shake

yeah, i am just using another method:

try { authResponse = await auth().createUserWithEmailAndPassword( [USER E-MAIL], [PASSWORD HASH]); } catch (e) { authResponse = await auth().signInWithEmailAndPassword([USER E-MAIL], [PASSWORD HASH]); }

milch-shake avatar Aug 15 '23 05:08 milch-shake

I'm also Facing the same issue is it resolved? @milch-shake

yeah, i am just using another method:

try { authResponse = await auth().createUserWithEmailAndPassword( [USER E-MAIL], [PASSWORD HASH]); } catch (e) { authResponse = await auth().signInWithEmailAndPassword([USER E-MAIL], [PASSWORD HASH]); }

so Still the Google sign in is not working right ? @milch-shake

DeeAndroid avatar Aug 16 '23 04:08 DeeAndroid

I'm also Facing the same issue is it resolved? @milch-shake

yeah, i am just using another method:

try { authResponse = await auth().createUserWithEmailAndPassword( [USER E-MAIL], [PASSWORD HASH]); } catch (e) { authResponse = await auth().signInWithEmailAndPassword([USER E-MAIL], [PASSWORD HASH]); }

the error is generated from createUserInFirestore function not from user registration function

ermohitpy avatar Sep 01 '23 12:09 ermohitpy

I research this error and find that , this error comes when we trying to set a field with a value of undefined in firebase firestore . So , i resolved this error by examine all the data-source which we send through createUserInFirebase function, So , i go to the same function in the nodemodule at location node_modules/@flyerhq/react-native-firebase-chat-core/lib/utils.js and add this code which simply remove the key which value undefined and the function works properly: `/** Creates {@link User} in Firebase to store name and avatar used on rooms list */ const createUserInFirestore = async (user) => { const dataToSet = { createdAt: firestore_1.default.FieldValue.serverTimestamp(), firstName: user.firstName, imageUrl: user.imageUrl, lastName: user.lastName, // Add other fields here if they have values updatedAt: firestore_1.default.FieldValue.serverTimestamp(), };

    // Remove fields with undefined values
    for (const key in dataToSet) {
      if (dataToSet.hasOwnProperty(key) && dataToSet[key] === undefined) {
        delete dataToSet[key];
      }
    }
  
    await (0, firestore_1.default)()
      .collection(exports.USERS_COLLECTION_NAME)
      .doc(user.id)
      .set(dataToSet);
};

exports.createUserInFirestore = createUserInFirestore; `

ermohitpy avatar Sep 04 '23 06:09 ermohitpy