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:
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);