Реагировать на собственную аутентификацию, используя laravel API бэкенда. - PullRequest
0 голосов
/ 02 апреля 2020

Я новичок в реакции-родной. В настоящее время я пытаюсь установить логин реактивной системы с помощью Laravel API. API, который я использовал, уже проверен и его работа. Но когда я попытался вставить реактив-нативный, он показывает ошибку, пока я вызывал API. Предупреждение в эмуляторе: Возможный необработанный отказ от обещания (id: 0): Ошибка типа: Ошибка сетевого запроса

Вот мой код.

import React, { Component } from 'react';
import {
    StyleSheet,
    View,
    TextInput,
    Text,
    TouchableOpacity,
    Alert,
    AsyncStorage,
} from 'react-native';
import {Actions} from 'react-native-router-flux';
import Logo from '../components/Logo';


export default class Login extends Component   {

    constructor(props) {
        super(props);
        this.state = {
            email: "",
            password: ""
        }
    };
    signup(){
        Actions.signup()
    }
    home(){
        Actions.home()
    }
    handleLogin = () => {
        fetch('http://localhost:8888/api/login',{
            method: 'POST',
            header:{
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                email: this.state.email,
                password: this.state.password,
            })
        })
        .then((response) => response.json())
        .then((res) => {

            if (res.success === true){

                alert(res.message)

            }else{
                alert(res.message)
            }

           alert('test')
        })
    }
    render() {
        return (
            <View style={styles.container}>
                <Logo/>

                <View style={styles.inputContainer}>
                    <TextInput style={styles.inputBox}
                        underlineColorAndroid='0,0,0,0'
                        placeholder='Email'
                        placeholderTextColor= 'grey'
                        keyboardType= 'email-address'
                        onChangeText={(text) => this.setState({email:text})}
                        onSubmitEditing={()=> this.password.focus()}
                    />

                    <TextInput style={styles.inputBox}
                        underlineColorAndroid='0,0,0,0'
                        placeholder='Password'
                        placeholderTextColor= 'grey'
                        secureTextEntry= {true}
                        ref={(input) => this.password = input}
                        onChangeText={(text) => this.setState({password:text})}

                    />
                    <TouchableOpacity style={styles.button} onPress={this.handleLogin}>
                        <Text style={styles.buttonText}>Login</Text>
                    </TouchableOpacity>
                </View>  

                <View style={styles.signupText}>
                    <Text>Don't have an account? </Text>
                    <TouchableOpacity onPress={this.signup}>
                        <Text style={styles.signupButton}>Signup</Text>
                    </TouchableOpacity>
                </View>

            </View>
        );
    }

}

Кто-нибудь знает, в чем проблема?

1 Ответ

0 голосов
/ 02 апреля 2020

Проблема решена настройкой adb и использованием команды adb reverse.

ПРИМЕР

adb reverse tcp:8081 tcp:3333

{ ссылка }

...