The Firebase JS SDK is now in BETA!
This EAP site is no longer maintained. See the official Firebase Documentation site for the latest documentation and information about the Firebase JS SDK.

Home > @firebase/auth > PhoneAuthProvider > verifyPhoneNumber

PhoneAuthProvider.verifyPhoneNumber() method

Starts a phone number authentication flow by sending a verification code to the given phone number.

Signature:

verifyPhoneNumber(phoneOptions: PhoneInfoOptions | string, applicationVerifier: ApplicationVerifier): Promise<string>;

Parameters

Parameter Type Description
phoneOptions PhoneInfoOptions | string
applicationVerifier ApplicationVerifier For abuse prevention, this method also requires a ApplicationVerifier. This SDK includes a reCAPTCHA-based implementation, RecaptchaVerifier.

Returns:

Promise<string>

A Promise for a verification ID that can be passed to PhoneAuthProvider.credential() to identify this flow..

Example 1

const provider = new PhoneAuthProvider(auth);
const verificationId = await provider.verifyPhoneNumber(phoneNumber, applicationVerifier);
// Obtain verificationCode from the user.
const authCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
const userCredential = await signInWithCredential(auth, authCredential);

Example 2

An alternative flow is provided using the signInWithPhoneNumber method.

const confirmationResult = signInWithPhoneNumber(auth, phoneNumber, applicationVerifier);
// Obtain verificationCode from the user.
const userCredential = confirmationResult.confirm(verificationCode);