首页 > 解决方案 > 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;

标签: javascriptfirebasereact-nativefirebase-authenticationone-time-password

解决方案


要使用实数,您应该在真实设备中运行项目,否则不会。在模拟器中,只有测试号码有效。


推荐阅读