React-Native Firebase/Auth- TypeError:undefined不是对象

q43xntqr  于 2023-04-22  发布在  React
关注(0)|答案(1)|浏览(149)

你好,我在为React-Native Firebase设置电子邮件和密码登录时遇到了麻烦。这是我在按下调用提交处理程序的按钮后不断得到的错误。

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

**编辑:**我发现问题出在import“import auth from '@react-native-firebase/auth';“这似乎是错误的时候,这是目前.如果我离开它在显示器是空白的,但如果我删除它它正常工作.我不太清楚为什么会这样.我使用的是M1 Macbook,并在过去有一些麻烦.如果有人可以帮助,这将是惊人的

这是我的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;

下面是错误的屏幕截图:Error after clicking submit button
任何你能告诉我我做错了什么的地方请告诉我,谢谢,安德鲁

mv1qrgav

mv1qrgav1#

你需要导入firebase,然后你可以尝试:

const submitHandler = () => {
    firebase.auth()
    .createUserWithEmailAndPassword(email, password)
    .then(() => {
      alert('User account created & signed in!');
    })

希望这能帮上忙

相关问题