voluptasmollitia
Version:
Monorepo for the Firebase JavaScript SDK
51 lines (31 loc) • 1.78 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [@firebase/auth](./auth.md) > [PhoneAuthProvider](./auth.phoneauthprovider.md) > [credential](./auth.phoneauthprovider.credential.md)
## PhoneAuthProvider.credential() method
Creates a phone auth credential, given the verification ID from [PhoneAuthProvider.verifyPhoneNumber()](./auth.phoneauthprovider.verifyphonenumber.md) and the code that was sent to the user's mobile device.
<b>Signature:</b>
```typescript
static credential(verificationId: string, verificationCode: string): PhoneAuthCredential;
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
| verificationId | string | The verification ID returned from [PhoneAuthProvider.verifyPhoneNumber()](./auth.phoneauthprovider.verifyphonenumber.md)<!-- -->. |
| verificationCode | string | The verification code sent to the user's mobile device. |
<b>Returns:</b>
[PhoneAuthCredential](./auth.phoneauthcredential.md)
The auth provider credential.
## Example 1
```javascript
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.
```javascript
const confirmationResult = await signInWithPhoneNumber(auth, phoneNumber, applicationVerifier);
// Obtain verificationCode from the user.
const userCredential = await confirmationResult.confirm(verificationCode);
```