I'm developing a user registration feature in a React Native app using Firebase Firestore to store user details. However, I keep encountering a TypeError during the Firestore document set operation.
Environment:
react-native": "0.76.5",
@react-native-firebase/app": "^21.6.2",
@react-native-firebase/firestore": "^21.6.2",
Testing Device/Emulator: [iOS and Android ]
I implemented user registration and data storage using Firestore in my React Native app. Here's what I expected and what I tried:
Expected: Successfully register a user and store their information (first name, last name, email, and registration timestamp) in Firestore.
Attempted: Used the Firestore set method to write user data after successful registration.
Code:
const handleRegister = async () => {
if (validateInput()) {
try {
const userCredential = await registerUserWithEmail(email, password);
console.log('User registered:', userCredential.user);
const db = firestore();
const userRef = db.collection('users').doc(userCredential.user.uid);
console.log('Firestore Reference:', userRef);
// Attempt to write to Firestore and log the process
userRef.set({
firstName: firstName,
lastName: lastName,
email: email,
createdAt: firestore.FieldValue.serverTimestamp()
})
.then(() => {
console.log('User data set in Firestore');
Alert.alert('Success', 'Account Created Successfully');
navigation.navigate('Login');
})
.catch(error => {
console.error('Firestore set error:', error);
Alert.alert('Registration Failed', error.message);
});
} catch (error) {
console.error('Registration Error:', error);
Alert.alert('Registration Failed', `${error.message} [${error.code}]`);
}
}
};
However, I keep encountering a TypeError when the set method is called, specifically complaining about documentSet not being a function. I expected the Firestore set operation to run without errors and store the user data.
Debugging Steps Taken:
Ensured the Firestore and Firebase SDKs are up-to-date. Checked Firestore permissions to ensure write access is enabled. Reviewed Firebase documentation to confirm usage of APIs. Added console logs to trace the values and confirm the presence of Firestore methods.
Error Message: [TypeError: this._firestore.native.documentSet is not a function (it is undefined)]
I'm developing a user registration feature in a React Native app using Firebase Firestore to store user details. However, I keep encountering a TypeError during the Firestore document set operation.
Environment:
react-native": "0.76.5",
@react-native-firebase/app": "^21.6.2",
@react-native-firebase/firestore": "^21.6.2",
Testing Device/Emulator: [iOS and Android ]
I implemented user registration and data storage using Firestore in my React Native app. Here's what I expected and what I tried:
Expected: Successfully register a user and store their information (first name, last name, email, and registration timestamp) in Firestore.
Attempted: Used the Firestore set method to write user data after successful registration.
Code:
const handleRegister = async () => {
if (validateInput()) {
try {
const userCredential = await registerUserWithEmail(email, password);
console.log('User registered:', userCredential.user);
const db = firestore();
const userRef = db.collection('users').doc(userCredential.user.uid);
console.log('Firestore Reference:', userRef);
// Attempt to write to Firestore and log the process
userRef.set({
firstName: firstName,
lastName: lastName,
email: email,
createdAt: firestore.FieldValue.serverTimestamp()
})
.then(() => {
console.log('User data set in Firestore');
Alert.alert('Success', 'Account Created Successfully');
navigation.navigate('Login');
})
.catch(error => {
console.error('Firestore set error:', error);
Alert.alert('Registration Failed', error.message);
});
} catch (error) {
console.error('Registration Error:', error);
Alert.alert('Registration Failed', `${error.message} [${error.code}]`);
}
}
};
However, I keep encountering a TypeError when the set method is called, specifically complaining about documentSet not being a function. I expected the Firestore set operation to run without errors and store the user data.
Debugging Steps Taken:
Ensured the Firestore and Firebase SDKs are up-to-date. Checked Firestore permissions to ensure write access is enabled. Reviewed Firebase documentation to confirm usage of APIs. Added console logs to trace the values and confirm the presence of Firestore methods.
Error Message: [TypeError: this._firestore.native.documentSet is not a function (it is undefined)]
The error looks to be in this part of your code:
// Attempt to write to Firestore and log the process
userRef.set({
firstName: firstName,
lastName: lastName,
email: email,
createdAt: firestore.FieldValue.serverTimestamp()
})
The error is letting you know that there is no set()
method available on the Document object. Instead use the setDoc()
like so:
setDoc
method to your imports:import { doc, setDoc } from "firebase/firestore";
// Attempt to write to Firestore and log the process
await setDoc(userRef, {
firstName: firstName,
lastName: lastName,
email: email,
createdAt: firestore.FieldValue.serverTimestamp()
})
invertase/react-native-firebase#8196
. – samthecodingman Commented Jan 10 at 1:41