1

Hi I'm Having trouble with setting up email and password login for React-Native Firebase. This is the error I keep getting after I have pressed the button which calls submit handler

TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[6], "@react-native-firebase/auth").auth')

Edit: I have discovered that the issue is occurring from the import "import auth from '@react-native-firebase/auth';" This seems to be erroring out when ever this is present. If I leave it in the display is blank, but if I remove it it works normally. I'm not too sure why this is the case. I am using a M1 Macbook and have had some troubles in the past. If anyone can help that would be amazing

This is my APP.js

// In App.js in a new project

import React, {useState} from 'react';
import { View, Text, TextInput, TouchableOpacity } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import ItemMenu from './src/components/ItemMenu';
import auth from '@react-native-firebase/auth';

function HomeScreen() {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>Home Screen</Text>
    </View>
  );
}

const Stack = createNativeStackNavigator();





function App() {
const [email,setEmail] = useState(" ");
const [password,setPassword] = useState(" ");

  const submitHandler = () => {
    auth()
    .createUserWithEmailAndPassword(email, password)
    .then(() => {
      alert('User account created & signed in!');
    })
    .catch(error => {
      if (error.code === 'auth/email-already-in-use') {
        console.log('That email address is already in use!');
      }

      if (error.code === 'auth/invalid-email') {
        console.log('That email address is invalid!');
      }

      console.error(error);
    });
  }

  return (
    <NavigationContainer>
      <View style={{paddingTop:50}}>
      <TextInput
      textContentType='email'
      placeholder='email:'
      onChangeText={text => setEmail(text)}
      />
      <TextInput
      textContentType='password'
      placeholder='password:'
      onChangeText={text => setPassword(text)}
      />
      </View>
      <TouchableOpacity
      onPress={submitHandler}
      style={{backgroundColor:"red",width:200,height:20}}
      />
    </NavigationContainer>
  );
}

export default App;

Here is a screen shot of the error: Error after clicking submit button

Anything you can tell me I'm doing wrong please let me know. Thank you, Andrew

Nero
  • 83
  • 1
  • 1
  • 5

1 Answers1

0

You will have to import firebase; then you may want to try:

  const submitHandler = () => {
    firebase.auth()
    .createUserWithEmailAndPassword(email, password)
    .then(() => {
      alert('User account created & signed in!');
    })
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83