This is the interface that defines the multi-factor related properties andoperations pertaining to afirebase.User.

Index

Properties

enrolledFactors

enrolledFactors:MultiFactorInfo[]

Returns a list of the user's enrolled second factors.

Methods

enroll

  • enroll(assertionMultiFactorAssertion, displayName?: string |null):Promise<void>
  • Enrolls a second factor as identified by thefirebase.auth.MultiFactorAssertion for the current user.On resolution, the user tokens are updated to reflect the change in theJWT payload.Accepts an additional display name parameter used to identify the secondfactor to the end user.Recent re-authentication is required for this operation to succeed.On successful enrollment, existing Firebase sessions (refresh tokens) arerevoked. When a new factor is enrolled, an email notification is sentto the user’s email.

    Error Codes

    auth/invalid-verification-code
    Thrown if the verification code is not valid.
    auth/missing-verification-code
    Thrown if the verification code is missing.
    auth/invalid-verification-id
    Thrown if the credential is afirebase.auth.PhoneAuthProvider.credential and the verificationID of the credential is not valid.
    auth/missing-verification-id
    Thrown if the verification ID is missing.
    auth/code-expired
    Thrown if the verification code has expired.
    auth/maximum-second-factor-count-exceeded
    Thrown if The maximum allowed number of second factors on a userhas been exceeded.
    auth/second-factor-already-in-use
    Thrown if the second factor is already enrolled on this account.
    auth/unsupported-first-factor
    Thrown if the first factor being used to sign in is not supported.
    auth/unverified-email
    Thrown if the email of the account is not verified.
    auth/requires-recent-login
    Thrown if the user's last sign-in time does not meet the securitythreshold. Usefirebase.User.reauthenticateWithCredential toresolve.
    example
    firebase.auth().currentUser.multiFactor.getSession()    .then(function(multiFactorSession){// Send verification codevar phoneAuthProvider =new firebase.auth.PhoneAuthProvider();var phoneInfoOptions = {phoneNumber: phoneNumber,session: multiFactorSession    };return phoneAuthProvider.verifyPhoneNumber(        phoneInfoOptions, appVerifier);    }).then(function(verificationId){// Store verificationID and show UI to let user enter verification code.    });var phoneAuthCredential =    firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode);var multiFactorAssertion =    firebase.auth.PhoneMultiFactorGenerator.assertion(phoneAuthCredential);firebase.auth().currentUser.multiFactor.enroll(multiFactorAssertion)    .then(function(){// Second factor enrolled.    });

    Parameters

    • assertion:MultiFactorAssertion

      The multi-factor assertion to enroll with.

    • Optional displayName:string |null

      The display name of the second factor.

    ReturnsPromise<void>

getSession

  • getSession():Promise<MultiFactorSession>
  • Returns the session identifier for a second factor enrollment operation.This is used to identify the current user trying to enroll a second factor.

    ReturnsPromise<MultiFactorSession>

    The promise that resolves with thefirebase.auth.MultiFactorSession.

    Error Codes

    auth/user-token-expired
    Thrown if the token of the user is expired.

unenroll

  • unenroll(optionMultiFactorInfo |string):Promise<void>
  • Unenrolls the specified second factor. To specify the factor to remove, passafirebase.auth.MultiFactorInfo object(retrieved fromenrolledFactors())or the factor's UID string.Sessions are not revoked when the account is downgraded. An emailnotification 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 theuser’s email.

    Error Codes

    auth/multi-factor-info-not-found
    Thrown if the user does not have a second factor matching theidentifier provided.
    auth/requires-recent-login
    Thrown if the user's last sign-in time does not meet the securitythreshold. Usefirebase.User.reauthenticateWithCredential toresolve.
    example
    var options = firebase.auth().currentUser.multiFactor.enrolledFactors;// Present user the option to unenroll.return firebase.auth().currentUser.multiFactor.unenroll(options[i])  .then(function(){// User successfully unenrolled selected factor.  }).catch(function(error){// Handler error.  });

    Parameters

    ReturnsPromise<void>

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 2022-07-27 UTC.