【发布时间】:2021-04-02 21:58:52
【问题描述】:
我已经使用 rnfirebase 实现了基于电话的身份验证。
使用的库:
"@react-native-firebase/app": "^10.3.0",
"@react-native-firebase/auth": "^10.3.1",
代码片段:
SignIn 发送 OTP 的方法:
newSignIn = async () => {
let phoneNumber = this.state.phone;
if (this.validatePhoneNumber(phoneNumber)) {
try {
const confirmation = await auth().signInWithPhoneNumber(phoneNumber);
ToastAndroid.show(JSON.stringify(confirmation), ToastAndroid.SHORT);
this.setState({ confirm: confirmation });
} catch (error) {
Alert.alert("Sorry!", "Error occurred. Check phone number.");
}
} else {
Alert.alert(
"Sorry!",
"Invalid Phone Number, make sure to add + country code."
);
}
}
当我在模拟器上测试它时,它可以很好地测试电话号码。但是当我创建发布 apk 并在我的手机上安装该 apk 时,有时它会发送 OTP 并且工作正常。但有时它不起作用,不发送任何 OTP。我已经尝试调试并观察到它正在进入无限等待在线:
const confirmation = await auth().signInWithPhoneNumber(phoneNumber);
【问题讨论】:
标签: javascript react-native firebase-authentication