mardi 28 avril 2020

Firebase phone number verification using web without recaptchaVerifier

i have used Firebase JavaScript code to send OTP to verify user phone number and it is working perfectly. But right now, i want to enhance the code by using it as personal API to verify phone number just by calling the URL and pass the phone number.

The only tree that fell on my way is Firebase "recaptchaVerifier".

Please, is there a way to use Firebase web phone number verification without recaptchaVerifier? Just only the phone number only.

<script type="text/javascript">
function onSignInSubmit(e) {
    e.preventDefault();
    if (isPhoneNumberValid()) {
      window.signingIn = true;
      updateSignInButtonUI();
      var phoneNumber = getPhoneNumberFromUserInput();
      var appVerifier = window.recaptchaVerifier;
      firebase.auth().signInWithPhoneNumber(phoneNumber, appVerifier)  //HERE IS WHERE THE DEVIL IS..
          .then(function(confirmationResult) {
            window.signingIn = false;
            updateSignInButtonUI();
            resetRecaptcha();
            // SMS sent. Prompt user to type the code from the message, then sign the
            // user in with confirmationResult.confirm(code).
            var code = window.prompt('Enter the verification code you received by SMS');
            if (code) {
              confirmationResult.confirm(code).then(function () {
                window.close();
              }).catch(function (error) {
                // User couldn't sign in (bad verification code?)
                console.error('Error while checking the verification code', error);
                window.alert('Error while checking the verification code:\n\n'
                    + error.code + '\n\n' + error.message)
              });
            }
          }).catch(function(error) {
            // Error; SMS not sent
            window.signingIn = false;
            console.error('Error during signInWithPhoneNumber', error);
            window.alert('Error during signInWithPhoneNumber:\n\n'
                + error.code + '\n\n' + error.message);
            updateSignInButtonUI();
            resetRecaptcha();
          });
    }
  }
</script>



Aucun commentaire:

Enregistrer un commentaire