Anonymous
Эмулятор Android не удалось подключиться на сервере
Сообщение
Anonymous » 09 сен 2025, 07:59
Я объяснил свою страницу входа ниже: < /h1>
проблема < /h1>
Я ожидаю, что приложение: < /p>
Принять учетные данные пользователя (электронная почта + пароль). ПРЕДУПРЕЖДЕНИЕ:
«Вход успешно» и перейдите к экрану панели приборной панели. /> code: < /strong> < /p>
Код: Выделить всё
import React, { useState } from 'react';
import {
StyleSheet,
View,
Text,
Image,
TextInput,
TouchableOpacity,
ImageBackground,
Alert,
} from 'react-native';
import axios from 'axios';
const LoginScreen = ({ navigation }) => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [rememberMe, setRememberMe] = useState(false);
const [showPassword, setShowPassword] = useState(false);
const handleLogin = async () => {
if (!email || !password) {
Alert.alert('Error', 'Please fill all fields');
return;
}
try {
const response = await axios.post('http://192.168.1.35:5000/login', {
email,
password,
});
if (response.data.success) {
const user = response.data.user;
Alert.alert('Login Successful', `Welcome, ${user.name}`);
navigation.replace('Dashboard', { user });
} else {
Alert.alert('Login Failed', response.data.message || 'Invalid credentials');
}
} catch (error) {
console.error('Login error:', error);
Alert.alert('Network Error', 'Failed to connect to server. Check Wi-Fi and IP.');
}
};
return (
Login
setShowPassword(!showPassword)}
style={styles.eyeButton}
activeOpacity={0.7}
>
{showPassword ? '🙈' : '👁️'}
setRememberMe(!rememberMe)}
/>
Remember Me
Forgot Password?
Login
);
};
export default LoginScreen;
const styles = StyleSheet.create({
background: { flex: 1, resizeMode: 'cover' },
overlay: {
flex: 1,
backgroundColor: 'rgba(0,0,0,0.4)',
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 20,
},
logoContainer: {
alignItems: 'center',
marginBottom: 40,
},
logo: {
width: 120,
height: 120,
borderRadius: 60,
},
card: {
width: '100%',
backgroundColor: '#fff',
borderRadius: 8,
padding: 20,
elevation: 5,
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 25,
textAlign: 'center',
color: '#333',
},
input: {
borderWidth: 1,
borderColor: '#bbb',
borderRadius: 6,
paddingHorizontal: 12,
paddingVertical: 10,
fontSize: 16,
marginBottom: 15,
},
passwordContainer: {
flexDirection: 'row',
alignItems: 'center',
marginBottom: 15,
},
eyeButton: {
paddingHorizontal: 10,
},
rememberContainer: {
flexDirection: 'row',
alignItems: 'center',
marginBottom: 15,
},
checkbox: {
width: 20,
height: 20,
borderWidth: 1,
borderColor: '#555',
marginRight: 10,
borderRadius: 4,
backgroundColor: '#fff',
},
checkboxChecked: {
backgroundColor: '#20B2AA',
},
rememberText: {
fontSize: 16,
color: '#555',
},
forgotPassword: {
color: '#20B2AA',
fontSize: 14,
textAlign: 'right',
},
button: {
backgroundColor: '#20B2AA',
paddingVertical: 12,
borderRadius: 6,
alignItems: 'center',
},
buttonText: {
color: '#fff',
fontSize: 18,
fontWeight: 'bold',
},
});
важные моменты
Я создал экран входа в REACT Native, который отправляет учетные данные пользователя локальному бэкэнд -серверу, работающему по адресу
http://192.168.1.33:5000/login axectios
. Электронные данные по электронной почте и пароля, приложение отправит запрос сообщения на бэкэнд, получит ответный ответ, покажите предупреждение о успехе входа в систему (
) и перейдите к экрану панели панели. Экриншот: < /strong>
введите описание изображения здесь < /p>
Что я хочу знать < /h1>
Мое код входа в систему правильным для того, чтобы я был достоверным, когда я предполагаю, что я предполагаю, когда я предполагаю, что я предполагаю, когда я предполагаю, что я предполагаю, когда я предполагаю, что я предполагаю, что я заполняю? /> Мне нужно что -то изменить в моем бэкэнд (формат ответа API) или только в коде фронта? < /li>
< /ul>
Подробнее здесь:
https://stackoverflow.com/questions/797 ... -in-server
1757393952
Anonymous
Я объяснил свою страницу входа ниже: < /h1> проблема < /h1> Я ожидаю, что приложение: < /p> Принять учетные данные пользователя (электронная почта + пароль). ПРЕДУПРЕЖДЕНИЕ: [b] «Вход успешно» [/b] и перейдите к экрану панели приборной панели. /> code: < /strong> < /p> [code] import React, { useState } from 'react'; import { StyleSheet, View, Text, Image, TextInput, TouchableOpacity, ImageBackground, Alert, } from 'react-native'; import axios from 'axios'; const LoginScreen = ({ navigation }) => { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [rememberMe, setRememberMe] = useState(false); const [showPassword, setShowPassword] = useState(false); const handleLogin = async () => { if (!email || !password) { Alert.alert('Error', 'Please fill all fields'); return; } try { const response = await axios.post('http://192.168.1.35:5000/login', { email, password, }); if (response.data.success) { const user = response.data.user; Alert.alert('Login Successful', `Welcome, ${user.name}`); navigation.replace('Dashboard', { user }); } else { Alert.alert('Login Failed', response.data.message || 'Invalid credentials'); } } catch (error) { console.error('Login error:', error); Alert.alert('Network Error', 'Failed to connect to server. Check Wi-Fi and IP.'); } }; return ( Login setShowPassword(!showPassword)} style={styles.eyeButton} activeOpacity={0.7} > {showPassword ? '🙈' : '👁️'} setRememberMe(!rememberMe)} /> Remember Me Forgot Password? Login ); }; export default LoginScreen; const styles = StyleSheet.create({ background: { flex: 1, resizeMode: 'cover' }, overlay: { flex: 1, backgroundColor: 'rgba(0,0,0,0.4)', justifyContent: 'center', alignItems: 'center', paddingHorizontal: 20, }, logoContainer: { alignItems: 'center', marginBottom: 40, }, logo: { width: 120, height: 120, borderRadius: 60, }, card: { width: '100%', backgroundColor: '#fff', borderRadius: 8, padding: 20, elevation: 5, }, title: { fontSize: 24, fontWeight: 'bold', marginBottom: 25, textAlign: 'center', color: '#333', }, input: { borderWidth: 1, borderColor: '#bbb', borderRadius: 6, paddingHorizontal: 12, paddingVertical: 10, fontSize: 16, marginBottom: 15, }, passwordContainer: { flexDirection: 'row', alignItems: 'center', marginBottom: 15, }, eyeButton: { paddingHorizontal: 10, }, rememberContainer: { flexDirection: 'row', alignItems: 'center', marginBottom: 15, }, checkbox: { width: 20, height: 20, borderWidth: 1, borderColor: '#555', marginRight: 10, borderRadius: 4, backgroundColor: '#fff', }, checkboxChecked: { backgroundColor: '#20B2AA', }, rememberText: { fontSize: 16, color: '#555', }, forgotPassword: { color: '#20B2AA', fontSize: 14, textAlign: 'right', }, button: { backgroundColor: '#20B2AA', paddingVertical: 12, borderRadius: 6, alignItems: 'center', }, buttonText: { color: '#fff', fontSize: 18, fontWeight: 'bold', }, }); [/code] важные моменты Я создал экран входа в REACT Native, который отправляет учетные данные пользователя локальному бэкэнд -серверу, работающему по адресу http://192.168.1.33:5000/login axectios . Электронные данные по электронной почте и пароля, приложение отправит запрос сообщения на бэкэнд, получит ответный ответ, покажите предупреждение о успехе входа в систему ([code]Alert.alert('Login Successful', ...)[/code]) и перейдите к экрану панели панели. Экриншот: < /strong> введите описание изображения здесь < /p> Что я хочу знать < /h1> Мое код входа в систему правильным для того, чтобы я был достоверным, когда я предполагаю, что я предполагаю, когда я предполагаю, что я предполагаю, когда я предполагаю, что я предполагаю, когда я предполагаю, что я предполагаю, что я заполняю? /> Мне нужно что -то изменить в моем бэкэнд (формат ответа API) или только в коде фронта? < /li> < /ul> Подробнее здесь: [url]https://stackoverflow.com/questions/79759506/android-emulator-failed-to-connect-in-server[/url]