Аутентификация Firebase не работает в моем собственном приложении React

Я новичок в реагировании на родной язык. Я создал форму, которая обрабатывает вход и регистрацию. Когда пользователь вводит адрес электронной почты и пароль, если адрес электронной почты и пароль действительны, пользователь получает сообщение о том, что он вошел в систему, и если адрес электронной почты не существует, создается новый пользователь, но, только создание пользовательской работы, вход в систему не работает

Моя форма входа:

import React, { Component } from 'react';
import { Text } from 'react-native';
import firebase from 'firebase';
import { Button, Card, CardSection, Input, Spinner } from './common';

class LoginForm extends Component{

    state={
        email:'[email protected]',
        password:'',
        error:'',
        loading:false
    };


    onButtonPress(){

        const { email, password} = this.state;
        this.setState({ error:'', loading:true });
        //Catch c'est pour gerer le cas d'echec de la requete precedante
        firebase.auth().signInWithEmailAndPassword(email, password)
        .then( this.onLoginSuccess.bind(this) )
        .catch( () => {
            firebase.auth().createUserWithEmailAndPassword(email, password)
            .then(this.onLoginSuccess.bind(this))
            .catch( this.onLoginFailed.bind(this) );
        });
    }

    onLoginSuccess(){
        this.setState({ 
            error: '', 
            loading: false,
            email : '',
            password :''
        });
        console.log("Logged succefully")
    }

    onLoginFailed(error){
        this.setState({
            error: 'Authentication Failed.', 
            loading: false
        });
        console.log(error.code);
        console.log(error.message);
    }

    renderButton(){
        if(this.state.loading){
            return <Spinner spinnerSize="small" />;
        }
        return (
            <Button onPress={this.onButtonPress.bind(this)}>Login</Button>
        )
    }

    render(){
        return (
            <Card>
                <CardSection>
                   <Input 
                   secureTextEntry={ false }
                        placeholder='[email protected]'
                        label='Email'
                        value={ this.state.email }
                        onChangeText={ emailValue => this.setState({email: emailValue}) }
                   />
                </CardSection>

                <CardSection>
                <Input 
                secureTextEntry={ true }
                    placeholder='password'
                    label='Password'
                    value={ this.state.password }
                    onChangeText={ pwdValue => this.setState({password: pwdValue}) }
                />
                </CardSection>

                <Text style={ styles.errorTextStyle }>{ this.state.error }</Text>

                <CardSection>
                    { this.renderButton() }
                </CardSection>
            </Card>
        );
    }
}

Код ошибки, который я получаю: auth/network-request-failed и сообщение об ошибке: A network error (such as timeout, interrupted connection or unreachable host) has occurred. Но у моих устройств есть подключение к Интернету. Добавление нового пользователя работает нормально.

Я сделал все, как сказано в официальном документе по этой ссылке: https://firebase.google.com/docs/auth/web/password-auth


person Christian Lisangola    schedule 03.08.2018    source источник


Ответы (1)


У меня такая же ошибка, и, немного покопавшись, я нашел причину:

emulator time issue

это происходит потому, что emulator и network имеют разное время. если вы вручную измените emulator время на то же, что и network, это сработает, по крайней мере, у меня это сработало.

person KaçakHavaSoluyanAdam    schedule 28.04.2019