MultiFactorResolver interface

ユーザーがサインインするために 2 番目の要素を指定する必要がある場合に、 MultiFactorErrorからの回復を容易にするために使用されるクラス。

サイン:

export interface MultiFactorResolver 

プロパティ

財産タイプ説明
ヒントマルチファクター情報[]現在のセッションのサインインを完了するために必要な 2 番目の要素のヒントのリスト。
セッションマルチファクターセッション現在のサインイン フローのセッション ID。第 2 要素サインインを完了するために使用できます。

メソッド

方法説明
解決サインイン(アサーション)ユーザーが 2 番目の要素のチャレンジを正常に完了したことを確認するMultiFactorAssertionを使用して、ユーザーが 2 番目の要素でサインインを完了するのを支援するヘルパー関数。

MultiFactorResolver.hints

現在のセッションのサインインを完了するために必要な 2 番目の要素のヒントのリスト。

サイン:

readonly hints: MultiFactorInfo[];

MultiFactorResolver.session

現在のサインイン フローのセッション ID。第 2 要素サインインを完了するために使用できます。

サイン:

readonly session: MultiFactorSession;

MultiFactorResolver.resolveSignIn()

ユーザーが 2 番目の要素のチャレンジを正常に完了したことを確認するMultiFactorAssertionを使用して、ユーザーが 2 番目の要素でサインインを完了するのを支援するヘルパー関数。

サイン:

resolveSignIn(assertion: MultiFactorAssertion): Promise<UserCredential>;

パラメーター

パラメータタイプ説明
アサーション多要素アサーションサインインを解決するための多要素アサーション。

戻り値:

Promise< UserCredential >

ユーザー資格情報オブジェクトで解決される Promise。

const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
const userCredential = await resolver.resolveSignIn(multiFactorAssertion);

let resolver;
let multiFactorHints;

signInWithEmailAndPassword(auth, email, password)
    .then((result) => {
      // User signed in. No 2nd factor challenge is needed.
    })
    .catch((error) => {
      if (error.code == 'auth/multi-factor-auth-required') {
        resolver = getMultiFactorResolver(auth, error);
        // Show UI to let user select second factor.
        multiFactorHints = resolver.hints;
      } else {
        // Handle other errors.
      }
    });

// The enrolled second factors that can be used to complete
// sign-in are returned in the `MultiFactorResolver.hints` list.
// UI needs to be presented to allow the user to select a second factor
// from that list.

const selectedHint = // ; selected from multiFactorHints
const phoneAuthProvider = new PhoneAuthProvider(auth);
const phoneInfoOptions = {
  multiFactorHint: selectedHint,
  session: resolver.session
};
const verificationId = phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, appVerifier);
// Store `verificationId` and show UI to let user enter verification code.

// UI to enter verification code and continue.
// Continue button click handler
const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
const userCredential = await resolver.resolveSignIn(multiFactorAssertion);