【发布时间】:2021-02-27 05:02:52
【问题描述】:
我已经从 RNFB 复制了电话身份验证的代码,几乎完全是从他们的网站...请参阅下面的代码(链接 here)。
当我使用“用于测试的电话号码”功能运行代码时由 Firebase 提供(即使用虚拟电话号码)......然后当我运行 signInWithPhoneNumber 函数时它不会在 FB 中创建用户......直到我运行它创建的 confirmCode 函数FB中的用户。据我了解,这就是它应该工作的方式。
但是....当我使用自己的电话号码运行MyPhoneAuthButton fn 时(即“真实”测试)...然后将 SMS 身份验证消息发送给我并且 用户立即在 FB 中创建而无需运行confirmCode fn。
为什么在测试和在产品中运行时表现不同?我应该为哪个流程编码?
任何帮助表示赞赏
const MyPhoneAuthButton = props => {
const [objConfirm, setObjConfirm] = useState(null);
const [code, setCode] = useState('');
// Handle the button press
const signInWithPhoneNumber = phoneNumber => {
auth()
.signInWithPhoneNumber(phoneNumber)
.then(confirmResult => {
setObjConfirm(confirmResult);
})
.catch(err => {
console.log('Invalid Phone Number', err.message);
});
};
const confirmCode = () => {
objConfirm
.confirm(code)
.then(user => {
console.log('User auth by phone OK', user);
.catch(err => {
console.log('Invalid code.', err.message);
});
};
<MyButton
onPress={() => {
signInWithPhoneNumber(props.telNum);
}}>
Sign in With Phone Number
</MyButton>
const signInWithPhoneNumber = phoneNumber => {
auth()
.signInWithPhoneNumber(phoneNumber)
.then(confirmResult => {
console.log('User successfully authorized via telNum');
setObjConfirm(confirmResult);
})
.catch(err => {
Alert.alert('Invalid Phone Number', err.message);
console.log('Invalid Phone Number', err.message);
});
};
【问题讨论】:
-
你能链接你获取代码的网址吗?我想仔细检查一下
-
完成 - 添加到原始帖子。我唯一改变的是使用
.then()而不是async await.....因为使用async await它不允许我使用catch错误 -
你渲染了确认按钮吗?你能展示你的渲染功能吗
-
添加到原帖
-
嗨@jamesmurphy,你不会在任何地方调用confirmCode函数。
标签: javascript react-native firebase-authentication react-native-android react-native-firebase