MultiFactorResolver interface

Lớp được sử dụng để hỗ trợ khôi phục từ MultiFactorError khi người dùng cần cung cấp yếu tố thứ hai để đăng nhập.

Chữ ký:

export interface MultiFactorResolver 

Của cải

Tài sản Kiểu Sự miêu tả
gợi ý Thông tin đa yếu tố [] Danh sách gợi ý về các yếu tố thứ hai cần thiết để hoàn tất quá trình đăng nhập cho phiên hiện tại.
phiên họp Phiên đa yếu tố Mã định danh phiên cho luồng đăng nhập hiện tại, có thể được sử dụng để hoàn tất đăng nhập yếu tố thứ hai.

phương pháp

Phương pháp Sự miêu tả
giải quyếtSignIn(khẳng định) Chức năng trợ giúp giúp người dùng hoàn tất đăng nhập bằng yếu tố thứ hai bằng cách sử dụng MultiFactorAssertion xác nhận rằng người dùng đã hoàn thành thành công thử thách yếu tố thứ hai.

MultiFactorResolver.hint

Danh sách gợi ý về các yếu tố thứ hai cần thiết để hoàn tất quá trình đăng nhập cho phiên hiện tại.

Chữ ký:

readonly hints: MultiFactorInfo[];

MultiFactorResolver.session

Mã định danh phiên cho luồng đăng nhập hiện tại, có thể được sử dụng để hoàn tất đăng nhập yếu tố thứ hai.

Chữ ký:

readonly session: MultiFactorSession;

MultiFactorResolver.resolveSignIn()

Chức năng trợ giúp giúp người dùng hoàn tất đăng nhập bằng yếu tố thứ hai bằng cách sử dụng MultiFactorAssertion xác nhận rằng người dùng đã hoàn thành thành công thử thách yếu tố thứ hai.

Chữ ký:

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

Thông số

Tham số Kiểu Sự miêu tả
quả quyết Khẳng định đa yếu tố Xác nhận đa yếu tố để giải quyết việc đăng nhập.

Trả về:

Lời hứa< Thông tin người dùng >

Lời hứa được giải quyết bằng đối tượng thông tin xác thực của người dùng.

Ví dụ

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

Ví dụ

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