React Native [Firebase错误:Firebase:错误(身份验证/网络请求失败)

kh212irz  于 2023-01-02  发布在  React
关注(0)|答案(1)|浏览(298)

因此,我有一个错误,以下教程在YouTube上,已经尝试在YouTube上找到如何解决它,但教程显示谷歌登录,但我不使用该功能
如果有人能帮忙的话非常感谢
还在学习火力,所以我是新来的
App.tsx

import React from 'react'
import { StatusBar } from 'expo-status-bar';
import { Alert, StyleSheet, View } from 'react-native';

import { getAuth, createUserWithEmailAndPassword, isSignInWithEmailLink, signInWithEmailAndPassword } from 'firebase/auth'
import {initializeApp} from 'firebase/app'
import { firebaseConfig } from './src/config/firebase';
import { Input, Button, Div, Text } from 'react-native-magnus';

import { NavigationContainer, useNavigation } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';

function HomeScreen(){
  return(
    <Div flex={1} justifyContent='center' alignSelf='center'>
      <Text>Hallo</Text>
    </Div>
  )
}

function LoginScreen(){

  const [email, setEmail] = React.useState('')
  const [password, setPassword] = React.useState('')

  const app = initializeApp(firebaseConfig)
  const auth = getAuth(app)
  
  const nav = useNavigation()

  const handleCreateAccount = () => {
    createUserWithEmailAndPassword(auth, email,password)
    .then((userCredential) => {
      console.log("Account Created")
      const user = userCredential.user
      console.log(user)
    })
    .catch((err) => {
      console.log(err)
      alert(err.message)
    })
  }

  const handleSignIn = () => {
    signInWithEmailAndPassword(auth, email, password)
    .then((userCredential) => {
      console.log("Signed In!") 
      const user = userCredential.user
      console.log(user)
      nav.navigate("Home")
    })
    .catch((err) => {
      console.log(err)
    })
  }

  return(
    <View style={styles.container}>
      <Div w={300}>
        <Input value={email} onChange={(val:any) => setEmail(val) } placeholder='Email..'  />
        <Input value={password} onChange={(val:any) => setPassword(val)} placeholder='Password..' mt={10} />
      </Div>
      <Div justifyContent='center'>
        <Button onPress={handleSignIn} w={100} mt={10}>
          Sign-In
        </Button>
        <Button onPress={handleCreateAccount} w={100} mt={10}>
          Register
        </Button>
      </Div>
      <StatusBar style="auto" />
    </View>
  )
}

const Stack = createNativeStackNavigator()
export default function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="Login" component={LoginScreen} options={{headerShown: false}} />
        <Stack.Screen name="Home" component={HomeScreen} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

错误是当我试图注册,因为你不能登录

vfh0ocws

vfh0ocws1#

当您的计算机没有正确连接到internet时,通常会抛出此类错误。
尝试检查设备上的internet connectivity,然后重试!

相关问题