MultiFactorUser interface Stay organized with collections Save and categorize content based on your preferences.
An interface that defines the multi-factor related properties and operations pertaining to aUser.
Signature:
exportinterfaceMultiFactorUserProperties
| Property | Type | Description |
|---|---|---|
| enrolledFactors | MultiFactorInfo[] | Returns a list of the user's enrolled second factors. |
Methods
| Method | Description |
|---|---|
| enroll(assertion, displayName) | Enrolls a second factor as identified by theMultiFactorAssertion for the user. |
| getSession() | Returns the session identifier for a second factor enrollment operation. This is used to identify the user trying to enroll a second factor. |
| unenroll(option) | Unenrolls the specified second factor. |
MultiFactorUser.enrolledFactors
Returns a list of the user's enrolled second factors.
Signature:
readonlyenrolledFactors:MultiFactorInfo[];MultiFactorUser.enroll()
Enrolls a second factor as identified by theMultiFactorAssertion for the user.
On resolution, the user tokens are updated to reflect the change in the JWT payload. Accepts an additional display name parameter used to identify the second factor to the end user. Recent re-authentication is required for this operation to succeed. On successful enrollment, existing Firebase sessions (refresh tokens) are revoked. When a new factor is enrolled, an email notification is sent to the user’s email.
Signature:
enroll(assertion:MultiFactorAssertion,displayName?:string|null):Promise<void>;Parameters
| Parameter | Type | Description |
|---|---|---|
| assertion | MultiFactorAssertion | The multi-factor assertion to enroll with. |
| displayName | string | null | The display name of the second factor. |
Returns:
Promise<void>
Example
constmultiFactorUser=multiFactor(auth.currentUser);constmultiFactorSession=awaitmultiFactorUser.getSession();// Send verification code.constphoneAuthProvider=newPhoneAuthProvider(auth);constphoneInfoOptions={phoneNumber:phoneNumber,session:multiFactorSession};constverificationId=awaitphoneAuthProvider.verifyPhoneNumber(phoneInfoOptions,appVerifier);// Obtain verification code from user.constphoneAuthCredential=PhoneAuthProvider.credential(verificationId,verificationCode);constmultiFactorAssertion=PhoneMultiFactorGenerator.assertion(phoneAuthCredential);awaitmultiFactorUser.enroll(multiFactorAssertion);// Second factor enrolled.MultiFactorUser.getSession()
Returns the session identifier for a second factor enrollment operation. This is used to identify the user trying to enroll a second factor.
Signature:
getSession():Promise<MultiFactorSession>;Returns:
Promise<MultiFactorSession>
The promise that resolves with theMultiFactorSession.
Example
constmultiFactorUser=multiFactor(auth.currentUser);constmultiFactorSession=awaitmultiFactorUser.getSession();// Send verification code.constphoneAuthProvider=newPhoneAuthProvider(auth);constphoneInfoOptions={phoneNumber:phoneNumber,session:multiFactorSession};constverificationId=awaitphoneAuthProvider.verifyPhoneNumber(phoneInfoOptions,appVerifier);// Obtain verification code from user.constphoneAuthCredential=PhoneAuthProvider.credential(verificationId,verificationCode);constmultiFactorAssertion=PhoneMultiFactorGenerator.assertion(phoneAuthCredential);awaitmultiFactorUser.enroll(multiFactorAssertion);MultiFactorUser.unenroll()
Unenrolls the specified second factor.
To specify the factor to remove, pass aMultiFactorInfo object (retrieved fromMultiFactorUser.enrolledFactors) or the factor's UID string. Sessions are not revoked when the account is unenrolled. An email notification is likely to be sent to the user notifying them of the change. Recent re-authentication is required for this operation to succeed. When an existing factor is unenrolled, an email notification is sent to the user’s email.
Signature:
unenroll(option:MultiFactorInfo|string):Promise<void>;Parameters
| Parameter | Type | Description |
|---|---|---|
| option | MultiFactorInfo | string | The multi-factor option to unenroll. |
Returns:
Promise<void>
- A
Promisewhich resolves when the unenroll operation is complete.
Example
constmultiFactorUser=multiFactor(auth.currentUser);// Present user the option to choose which factor to unenroll.awaitmultiFactorUser.unenroll(multiFactorUser.enrolledFactors[i])Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-01-19 UTC.