LOG [FirebaseError: Firebase: A network AuthError (such as timeout, interrupted…
- User
LOG [FirebaseError: Firebase: A network AuthError (such as timeout, interrupted connection or unreachable host) has occurred. (auth/network-request-failed).] LOG No user is signed in i have this err but my connection ok and nothing wrong with firewall and devices, user can register himself, i see data there but user cannot log in. i think there is problelm with code import { Text, View, TextInput, Pressable, ScrollView, Alert, TouchableHighlight, TouchableOpacity } from 'react-native'; import { gStyle } from '../styles/style'; import Header from '../components/Header'; import Footer from '../components/Footer'; import { useNavigation } from '@react-navigation/native'; import { firebase } from '../Firebase/firebase'; import 'firebase/compat/auth'; import 'firebase/compat/database'; import 'firebase/compat/firestore'; import React, {useState} from 'react';
export default function Auth() { const navigation = useNavigation(); const [email, setEmail] = useState(''); const [phone, setPhone] = useState(''); const [password, setPassword] = useState(''); const [errorMessage, setErrorMessage] = React.useState(null); const handleLogin=()=>{ if (!email || !password) { Alert.alert('Ошибка!','Неверная почта или пароль'); return; } firebase.auth().signInWithEmailAndPassword(email, password) .then(()=>{ const user = firebase.auth().currentUser; user.getIdToken() .then((token) => { // do something with the token }) .catch((error) => { console.log(error); }); navigation.navigate('Profile'); }) .catch((error) => { setErrorMessage(error.message); console.log(error); }); }; firebase.auth().onAuthStateChanged(user => { if(user) { console.log(user
${user.uid} is signed in); } else { console.log('No user is signed in'); } }); return (<Text style={gStyle.header}>Войти в личный{"\n"}кабинет</Text> <View style={gStyle.AuthContainer}> <View style={gStyle.AuthBox}> <View style={gStyle.AuthBox1}> <Text style={gStyle.AuthName}>Почта</Text> <TextInput style={gStyle.AuthInfo} onChangeText={setEmail} /> </View> <View style={gStyle.AuthBox1}> <Text style={gStyle.AuthName}>Пароль</Text> <TextInput style={gStyle.AuthInfo} onChange={setPassword} secureTextEntry={true} /> </View> </View> <Pressable style={gStyle.AuthForgotPassword} onPress={''}> <Text style={gStyle.AuthPass}>Забыли пароль?</Text> </Pressable> <TouchableOpacity style={gStyle.AuthLogin} onPress={handleLogin}> <Text style={gStyle.AuthBtnLogin}>Войти</Text> </TouchableOpacity> <Pressable onPress={()=>navigation.navigate('Registration')} > <Text style={gStyle.AuthRegistr}>Я не зарегистрирован(а)</Text> </Pressable> </View> </View> <Footer/> </ScrollView> </View>); }
i need that when user click on Войти he log in, it checks email and password
- Assistant
and navigates to the Profile screen if the login is successful. It also needs to handle errors and display them to the user if there are any issues with the login process.
Based on the error message you provided, it seems there is an issue with the network connection when trying to authenticate the user. This could be caused by a variety of factors, including poor connectivity or a problem with Firebase.
One way to troubleshoot this issue is to try logging in with different network connections (such as cellular data or a different Wi-Fi network) to see if the problem persists. You can also check the Firebase console to see if there are any reported issues or outages with the authentication service.
In terms of your code, it looks like you are handling the login process correctly by calling
firebase.auth().signInWithEmailAndPassword()and passing in the email and password values. However, you may want to add some additional error handling logic to display the error message to the user if there are any issues with the login.