Whenever I click the submit button on my code to upload data to my firebase database, I get this error :
ERROR [2024-01-21T03:39:39.733Z] @firebase/firestore: Firestore (10.7.2): INTERNAL UNHANDLED ERROR: TypeError: Cannot read property 'includes' of undefined
i have tried uninstalling the node modules and specifically firebase but nothing is working. I tried making a new firebase account and it still doesn’t work. I cannot figure it out.
import { StyleSheet, Text, View, TextInput, Button } from 'react-native';
import { getAuth } from 'firebase/auth';
import { getFirestore, doc, setDoc } from 'firebase/firestore';
import app from '../config/FirebaseConfig'; // Adjust this path as necessary
const DataInput = () => {
const [monthOrderTotal, setMonthOrderTotal] = useState('');
const [monthDollarAmount, setMonthDollarAmount] = useState('');
const firestore = getFirestore(app);
const auth = getAuth();
const handleSave = async () => {
const user = auth.currentUser;
if (user) {
try {
const userData = {
monthOrderTotal,
monthDollarAmount
};
// Merge the new data into the existing document or create a new document if it doesn't exist
await setDoc(doc(firestore, 'users', user.uid), userData, { merge: true });
console.log('Data saved successfully');
} catch (error) {
console.error('Error saving data: ', error);
}
} else {
console.error('No user logged in');
}
};
return (
<View style={styles.container}>
<Text>Data Input Screen</Text>
<TextInput
style={styles.input}
placeholder="Month Order Total"
value={monthOrderTotal}
onChangeText={setMonthOrderTotal}
keyboardType="numeric"
/>
<TextInput
style={styles.input}
placeholder="Month Dollar Amount"
value={monthDollarAmount}
onChangeText={setMonthDollarAmount}
keyboardType="numeric"
/>
<Button title="Save" onPress={handleSave} />
</View>
);
};
export default DataInput;
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center'
},
input: {
height: 40,
margin: 12,
borderWidth: 1,
padding: 10,
width: '80%'
}
});
2
Answers
function HomeView() {
i had the same issue
ERROR [2024-01-21T08:07:48.756Z] @firebase/firestore: Firestore (10.7.2): INTERNAL UNHANDLED ERROR: TypeError: Cannot read property ‘includes’ of undefined
at isSafari
It’s an issue with Firestore 10.7.2
Just downgrade to version 10.7.1 and it should work fine.
Check this issue on GitHub