The Firebase JS SDK is now in BETA!
This EAP site is no longer maintained. See the official Firebase Documentation site for the latest documentation and information about the Firebase JS SDK.

Home > @firebase/auth > MultiFactorUser > getSession

MultiFactorUser.getSession() method

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