skip to Main Content

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


  1. function HomeView() {

      const navigation = useNavigation();
    
    
      const addDocument = async () => {
        try {
          const docRef = await addDoc(collection(firestore, "your_collection"), {
            field1: "value1",
            field2: "value2",
          });
          console.log("Document written with ID: ", docRef.id);
        } catch (e) {
          console.error("Error adding document: ", e);
        }
      };
    
      return (
        <View className="flex justify-center items-center relative top-60">
          <Text> D-ALERT LOGO </Text>
    
          <TouchableOpacity className="ml-5 mt-60"
              onPress={() => {
                navigation.navigate("Login")
              }}
            >
              <Text className="text-blue-500 text-lg font-bold">LOG IN</Text>
            </TouchableOpacity>
    
    
            <TouchableOpacity onPress={()=> addDocument()}>
                  <View>
                      <Text>test</Text>
                  </View>
              </TouchableOpacity>
        </View>
      )
    }
    

    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

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search