MultiFactorResolver interface

當使用者需要提供第二個因素進行登入時,該類別可協助從MultiFactorError中復原。

簽名:

export interface MultiFactorResolver 

特性

財產類型描述
提示多因素資訊[]完成目前會話登入所需的第二個因素的提示清單。
會議多因素會話目前登入流程的會話標識符,可用於完成第二因素登入。

方法

方法描述
解決登入(斷言)幫助程式功能,幫助使用者使用MultiFactorAssertion完成第二因素登錄,確認使用者已成功完成第二因素挑戰。

MultiFactorResolver.hints

完成目前會話登入所需的第二個因素的提示清單。

簽名:

readonly hints: MultiFactorInfo[];

MultiFactorResolver.session

目前登入流程的會話標識符,可用於完成第二因素登入。

簽名:

readonly session: MultiFactorSession;

MultiFactorResolver.resolveSignIn()

幫助程式功能,幫助使用者使用MultiFactorAssertion完成第二因素登錄,確認使用者已成功完成第二因素挑戰。

簽名:

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

參數

範圍類型描述
斷言多因素斷言用於解決登入問題的多因素斷言。

返回:

承諾<使用者憑證>

使用使用者憑證物件解析的承諾。

例子

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