Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
milch-shake opened this issue May 22, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@milch-shake
Copy link

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 milch-shake added the bug Something isn't working label May 22, 2023
@milch-shake milch-shake changed the title createUserInFirestore => Error: Unsupported field value: undefined React Native createUserInFirestore => Error: Unsupported field value: undefined May 22, 2023
@DeeAndroid
Copy link

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

@milch-shake
Copy link
Author

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]);
}

@DeeAndroid
Copy link

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

@ermohitpy
Copy link

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
Copy link

ermohitpy commented Sep 4, 2023

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;
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants