javascript - React Native firebase OTP 仅适用于测试号码,不适用于我的真实号码
问题描述
我按照本指南:https ://rnfirebase.io/auth/phone-auth将 OTP 添加到我的应用程序,但它仅适用于我在 firebase 控制台网站上设置的测试号码,当我输入我的真实号码时什么也不做。下面的代码:
function Phone() {
// If null, no SMS has been sent
const [confirm, setConfirm] = useState(null);
const [code, setCode] = useState('');
// Handle the button press
async function signInWithPhoneNumber(phoneNumber) {
const confirmation = await auth().signInWithPhoneNumber(phoneNumber);
setConfirm(confirmation);
}
async function confirmCode() {
try {
await confirm.confirm(code);
} catch (error) {
console.log('Invalid code.');
}
}
//+20 123 456 9879
if (!confirm) {
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Button
title="Phone Number Sign In"
onPress={() => signInWithPhoneNumber('//My real number')}
/>
</View>
);
}
return (
<>
<TextInput value={code} onChangeText={text => setCode(text)} />
<Button title="Confirm Code" onPress={() => confirmCode()} />
</>
);
}
export default Phone;
解决方案
要使用实数,您应该在真实设备中运行项目,否则不会。在模拟器中,只有测试号码有效。
推荐阅读
- python-3.x - 问题返回用户
- python - 关键错误,并在 Pandas、Python 中更改数据框
- python - 使用类层次结构和 mypy 进行静态类型测试
- c++ - 有没有办法检查用户输入是否是数字?
- swiftui - NavigationView 中的 SwiftUI 自定义动画过渡?
- java - 使用注释修改 REST 参数 - Java EE8
- bash - ZSH:在脚本文件中执行函数
- c++ - 黑客等级 C++ 上的 Mini-Max Sum
- java - 如何减去两个时间值?
- react-native - 如何读取本地 css 文件以将其注入 react-native WebView?