簡體   English   中英

使用 firebase 從 React Native 發送 OTP 時遇到問題

[英]Facing issue while sending OTP from react native using firebase

我正在嘗試使用 firebase 從 react-native 發送 OTP,但它不起作用。 我收到錯誤消息“找不到主機名”。 我想了解此發送 OTP 在使用 firebase 的移動應用程序中如何工作。我可以通過僅安裝 the.apk 而不是將 the.apk 上傳到 Play 商店來測試移動/本地的 OTP 功能嗎?

我做了以下配置步驟:

  1. 在 firebase 控制台創建項目。
  2. 在身份驗證下選擇電話作為登錄方法。
  3. 添加了移動應用程序並下載了 google-services.json 並在我的代碼中的 firebase 屬性中使用了相同的配置。

發送一次性密碼

const phoneProvider = new firebase.auth.PhoneAuthProvider();
console.log('Phone provider ', phoneProvider);
phoneProvider.verifyPhoneNumber(this.state.mobileNumber, this.recaptchaVerifier.current).then((phoneAuthSnapshot) => {
    // verification sent
    console.log('Verification code sent');
    this.setState({
        status: 'Confirmation code sent.',
        verificationId: phoneAuthSnapshot.verificationId,
        //showCodeInput: true // shows input field such as react-native-confirmation-code-field
    });

驗證一次性密碼

firebase
  .auth()
  .signInWithCredential(credential)
  .then((result) => {
    // Do something with the results here
    console.log(result);
    this.props.navigation.navigate('Home');
  }).catch((error) => {
    console.log('error sending code ', error);
    this.setState({
      showFailureDialog: true,
      failureMessage: 'OTP did not matched ' + error
    })

您可以通過在手機中安裝 apk 來測試 OTP 功能。 您還可以在 firebase 控制台中包含一些隨機數和 otp 以檢查身份驗證過程。 (身份驗證 -> 登錄方法 -> 電話 -> 添加電話號碼進行測試)

要設置 OTP 身份驗證,幾乎所有您需要做的就是將您應用的 SHA-1 指紋添加到您的應用中。 (項目設置 -> 您的應用程序 -> SHA 證書指紋,適用於 Android)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM