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 > credential

PhoneAuthProvider.credential() method

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

Signature:

static credential(verificationId: string, verificationCode: string): PhoneAuthCredential;

Parameters

Parameter Type Description
verificationId string The verification ID returned from PhoneAuthProvider.verifyPhoneNumber().
verificationCode string The verification code sent to the user's mobile device.

Returns:

PhoneAuthCredential

The auth provider credential.

Example 1

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

Example 2

An alternative flow is provided using the signInWithPhoneNumber method.

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