android - 收到短信后立即过期的短信代码
问题描述
我有一个应用程序,您可以通过电话号码登录
输入电话号码后,我收到短信代码
将打开一个新屏幕,我可以在其中输入此代码
当我输入代码时,我得到代码已过期的信息
标志:第一屏
onSignIn() {
const {code, phoneNumber} = this.state;
const newNumber = '+' + code + phoneNumber;
if (newNumber.length > 10) {
firebase
.auth()
.signInWithPhoneNumber(newNumber)
.then(confirmResult => {
this.setState({result: confirmResult});
const navigateAction = NavigationActions.navigate({
routeName: 'SecurityCode',
params: {phoneAuthResponse: confirmResult},
});
this.props.navigation.dispatch(navigateAction);
})
.catch(error => {
if (error.message === 'TOO SHORT') {
alert('Please enter a valid phone number');
} else {
alert(error.message);
}
});
} else {
alert('Please Enter Your Number');
}
}
确认:第二个屏幕
onConfirmCode() {
const {securityCode} = this.state;
if (securityCode.length > 5) {
this.props.navigation.state.params.phoneAuthResponse
.confirm(securityCode)
.then(async user => {
const ref = firebase.database().ref(`users/${user.uid}`);
ref.once('value', async snapshot => {
let data = snapshot.val();
if (!data) {
this.props.navigation.navigate('CreateProfile', {
user: {uid: user.uid, phone_number: user.phoneNumber},
});
} else {
this.props.reduxLoginUser(data);
this.props.navigation.navigate('InviteContacts');
}
});
})
.catch(error => console.warn(error.message));
} else {
alert('Please enter the 6 digit code');
}
}
做错了什么?
解决方案
检查是否已创建用户(您可以在 Firebase 项目页面上执行此操作)
如果它被创建,那么还有另一个问题需要解决
您必须捕捉到用户已创建并在登录后转到屏幕
推荐阅读
- r - R:如何将对象及其值放入数据框中
- regex - sed 脚本删除空行之前的行
- python - 将经过身份验证的用户关联到形成对象 Djano
- c++ - CMake'ifying Boost Jam 文件:Windows 库名称
- wordpress - Woocommerce - 我需要在商店和产品页面显示一个单位的价格(7 美元),但收取产品的实际价值(100 件)
- c# - 检查数据表是否包含某个值
- python - 使用 Conda 和 matplotlib 的英特尔 MKL 错误:macOS 上的“库未加载:@rpath/libiomp5.dylib”
- html - 和有什么区别和
- r - 在R中组合数据帧而不用空白覆盖数据
- python - 使用两个 Pandas 数据框创建列表列表