gpt4 book ai didi

android - Firebase电话号码认证,每次验证码都过期

转载 作者:行者123 更新时间:2023-11-29 16:34:11 24 4
gpt4 key购买 nike

我在我的应用程序中添加了 firebase 身份验证。如果我在手机中添加其他用户的电话号码,效果很好。但是,如果我添加我的电话号码,它会发送 OTP,但是当我每次输入该 OTP 时,它都会显示错误“短信代码已过期”。

有没有自动认证?有什么我想念的吗?

我使用下面的代码发送 OTP

 firebase.auth().signInWithPhoneNumber(this.state.countryCode + this.state.phoneNumber)
.then(confirmResult => {


this.setState({
progressVisible: false
})

console.log("confirmResult is " + confirmResult)

AsyncStorage.setItem('CountryCode', this.state.countryCode);
AsyncStorage.setItem('PhoneNumber', this.state.phoneNumber);


this.props.navigation.navigate("OtpScreen", {
confirmResult, isConnected: this.state.isConnected
})
})

我使用下面的代码来验证 OTP

 this.state.confirmResult.confirm(this.state.otpText)
.then(user => {

// this.setState({
// progressVisible: false
// })
console.log("Debug starts, 2");
this.hitAuthApi()

})
.catch(error => {
this.setState({
progressVisible: false
})
setTimeout(() => {
Alert.alert("Error" + error);
}, 100)
});

最佳答案

有一个用于自动登录的 firebase 内置监听器,需要在组件中初始化。它会在 android 中自动检测短信。

this.unsubscribe = firebase.auth().onAuthStateChanged((user) => {
// alert(JSON.stringify(user))
if (user) {


//hit Api
} else {
// User has been signed out, reset the state

}
});

关于android - Firebase电话号码认证,每次验证码都过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53078504/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com