[ Web Proxy ]
URL:
Viewing: https://firebase.google.com/docs/reference/js/auth.multifactoruser [Back]  [Original]

MultiFactorUser interface  |  Firebase JavaScript API reference Skip to main content
Overview Fundamentals AI Build Run Reference Samples
Firebase [Firebase]
Send feedback

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 a User.

Signature:

export interface MultiFactorUser 

Properties

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 the MultiFactorAssertion 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:

readonly enrolledFactors: MultiFactorInfo[];

MultiFactorUser.enroll()

Enrolls a second factor as identified by the MultiFactorAssertion 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 users 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

const multiFactorUser = multiFactor(auth.currentUser);
const multiFactorSession = await multiFactorUser.getSession();

// Send verification code.
const phoneAuthProvider = new PhoneAuthProvider(auth);
const phoneInfoOptions = {
  phoneNumber: phoneNumber,
  session: multiFactorSession
};
const verificationId = await phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, appVerifier);

// Obtain verification code from user.
const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
await multiFactorUser.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 the MultiFactorSession.

Example

const multiFactorUser = multiFactor(auth.currentUser);
const multiFactorSession = await multiFactorUser.getSession();

// Send verification code.
const phoneAuthProvider = new PhoneAuthProvider(auth);
const phoneInfoOptions = {
  phoneNumber: phoneNumber,
  session: multiFactorSession
};
const verificationId = await phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, appVerifier);

// Obtain verification code from user.
const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
await multiFactorUser.enroll(multiFactorAssertion);

MultiFactorUser.unenroll()

Unenrolls the specified second factor.

To specify the factor to remove, pass a MultiFactorInfo object (retrieved from MultiFactorUser.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 users email.

Signature:

unenroll(option: MultiFactorInfo | string): Promise<void>;

Parameters

Parameter Type Description
option MultiFactorInfo | string The multi-factor option to unenroll.

Returns:

Promise<void>

Example

const multiFactorUser = multiFactor(auth.currentUser);
// Present user the option to choose which factor to unenroll.
await multiFactorUser.unenroll(multiFactorUser.enrolledFactors[i])

Send feedback

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-01-19 UTC.

Need to tell us more? [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-01-19 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page