Constructor

PhoneAuthProvider

new PhoneAuthProvider(auth)

Phone number auth provider.

Parameter

auth

Optional

firebase.auth.Auth

The Firebase Auth instance in which sign-ins should occur. Uses the default Auth instance if unspecified.

Value may be null.

Implements
firebase.auth.AuthProvider

Example

// 'recaptcha-container' is the ID of an element in the DOM.
var applicationVerifier = new firebase.auth.RecaptchaVerifier(
    'recaptcha-container');
var provider = new firebase.auth.PhoneAuthProvider();
provider.verifyPhoneNumber('+16505550101', applicationVerifier)
    .then(function(verificationId) {
      var verificationCode = window.prompt('Please enter the verification ' +
          'code that was sent to your mobile device.');
      return firebase.auth.PhoneAuthProvider.credential(verificationId,
          verificationCode);
    })
    .then(function(phoneCredential) {
      return firebase.auth().signInWithCredential(phoneCredential);
    });

Properties

PROVIDER_ID

static

string

providerId

string

Implements
firebase.auth.AuthProvider#providerId

Methods

credential

static

credential(verificationId, verificationCode) returns firebase.auth.AuthCredential

Creates a phone auth credential, given the verification ID from firebase.auth.PhoneAuthProvider#verifyPhoneNumber and the code that was sent to the user's mobile device.

Error Codes

auth/missing-verification-code
Thrown if the verification code is missing.
auth/missing-verification-id
Thrown if the verification ID is missing.

Parameter

verificationId

string

The verification ID returned from firebase.auth.PhoneAuthProvider#verifyPhoneNumber.

verificationCode

string

The verification code sent to the user's mobile device.

Returns

non-null firebase.auth.AuthCredential 

verifyPhoneNumber

verifyPhoneNumber(phoneNumber, applicationVerifier) returns firebase.Promise containing string

Starts a phone number authentication flow by sending a verification code to the given phone number. Returns an ID that can be passed to firebase.auth.PhoneAuthProvider#credential to identify this flow.

For abuse prevention, this method also requires a firebase.auth.ApplicationVerifier. The Firebase Auth SDK includes a reCAPTCHA-based implementation, firebase.auth.RecaptchaVerifier.

Error Codes

auth/captcha-check-failed
Thrown if the reCAPTCHA response token was invalid, expired, or if this method was called from a non-whitelisted domain.
auth/invalid-phone-number
Thrown if the phone number has an invalid format.
auth/missing-phone-number
Thrown if the phone number is missing.
auth/quota-exceeded
Thrown if the SMS quota for the Firebase project has been exceeded.
auth/user-disabled
Thrown if the user corresponding to the given phone number has been disabled.

Parameter

phoneNumber

string

The user's phone number in E.164 format (e.g. +16505550101).

applicationVerifier

firebase.auth.ApplicationVerifier

Value must not be null.

Returns

non-null firebase.Promise containing string A Promise for the verification ID.