react-native-firebase-chat-core
react-native-firebase-chat-core copied to clipboard
React Native createUserInFirestore => Error: Unsupported field value: undefined
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.
I'm also Facing the same issue is it resolved? @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]); }
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
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
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; `