我尝试使用 Expo 构建一个电子商务应用程序并做出本机反应,但我遇到网络错误,谷歌服务在设备上处于活动状态(Android 模拟器和 IOS 真实 iPhone),并且我已连接到我的 Google 帐户。
我也尝试阻止页面重新加载,但没有任何改变。经过一番研究后,我发现我并不是唯一一个面临此错误的人,我没有找到任何有价值的答案,所以我最终来到了这里。
这是我的代码:
const LoginScreen = () => {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [isSignedIn, setIsSignedIn] = useState(false);
const handleCreateAccount = (e) => {
e.preventDefault();
createUserWithEmailAndPassword(authentification, email, password)
.then((userCredential) => {
console.log(userCredential);
})
.catch((error) => {
console.log(error.message);
});
};
const handleSignIn = (e) => {
e.preventDefault();
signWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
console.log("Signed in!");
const user = userCredential.user;
console.log(user);
})
.catch((error) => {
console.log(error);
Alert.alert(error.message);
});
};
<ScrollView
contentContainerStyle={{
flex: 1,
width: "100%",
height: "100%",
alignItems: "center",
justifyContent: "center",
}}
>
<BlurView intensity={100}>
<View style={styles.login}>
<Image
source={{ uri: profilePicture }}
style={styles.profilePicture}
/>
<Text style={{ fontSize: 17, fontWeight: "400", color: "white" }}>
email
</Text>
<TextInput
onChangeText={(text) => setEmail(text)}
style={styles.input}
placeholder="[email protected]"
keyboardType="email-address"
textContentType="emailAddress"
/>
<Text style={{ fontSize: 17, fontWeight: "400", color: "white" }}>
mot de passe
</Text>
<TextInput
onChange={(text) => setPassword(text)}
style={styles.input}
placeholder="your password"
secureTextEntry={true}
/>
<Button
onPress={handleSignIn}
title="Connexion"
buttonStyle={{
width: 250,
height: 40,
borderRadius: 10,
backgroundColor: "#00CFEB90",
alignItems: "center",
justifyContent: "center",
marginVertical: 10,
borderColor: "#fff",
borderWidth: 2,
}}
type="outline"
titleStyle={{ color: "white", fontSize: 17 }}
/>
<Button
onPress={handleCreateAccount}
title="Créer un compte"
buttonStyle={{
width: 250,
height: 40,
borderRadius: 10,
backgroundColor: "#6792F090",
alignItems: "center",
justifyContent: "center",
marginVertical: 10,
borderColor: "#fff",
borderWidth: 2,
}}
type="outline"
titleStyle={{ color: "white", fontSize: 17 }}
/>
</View>
</BlurView>
</ScrollView>
所以我需要帮助。
万一它对某人有帮助。 我遇到了同样的问题并浪费了很多时间进行调查。 事实证明,就我而言,这只是 firebase 层中的 DNS 问题。 模拟器 URL 中的
localhost
未解析。
我用 127.0.0.1
替换了它,并且工作正常。
auth/network-request-failed
错误可能特别具有误导性,因为它似乎是由于多种不同的原因而出现的。我见过以下任何一个:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
我有
connectAuthEmulator(auth, "http://127.0.0.1", "9099");
现在我有了
connectAuthEmulator(auth, "http://127.0.0.1:9099");
并且有效。