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