MultiFactorResolver interface

用于在用户需要提供第二重身份验证凭据才能登录时,用于促进从 MultiFactorError 恢复的类。

签名

export interface MultiFactorResolver 

属性

属性 类型 说明
提示 MultiFactorInfo[] 完成当前会话登录所需的第二个因素的提示列表。
session MultiFactorSession 当前登录流程的会话标识符,可用于完成第二重身份验证。

方法

方法 说明
resolveSignIn(断言) 辅助函数,用于帮助用户通过第二重身份验证完成登录,它使用 MultiFactorAssertion 确认用户已成功完成第二重身份验证。

MultiFactorResolver.hints

完成当前会话登录所需的第二个因素的提示列表。

签名

readonly hints: MultiFactorInfo[];

MultiFactorResolver.session

当前登录流程的会话标识符,可用于完成第二重身份验证。

签名

readonly session: MultiFactorSession;

MultiFactorResolver.resolveSignIn()

辅助函数,用于帮助用户通过第二重身份验证完成登录,它使用 MultiFactorAssertion 确认用户已成功完成第二重身份验证。

签名

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

参数

参数 类型 说明
断言 MultiFactorAssertion 用于解析登录的多重身份验证断言。

返回

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