MultiFactorResolver interface

사용자가 로그인하기 위해 두 번째 요소를 제공해야 할 때 MultiFactorError 에서 쉽게 복구하는 데 사용되는 클래스입니다.

서명:

export interface MultiFactorResolver 

속성

재산 유형 설명
힌트 멀티팩터정보 [] 현재 세션에 대한 로그인을 완료하는 데 필요한 두 번째 요소에 대한 힌트 목록입니다.
세션 MultiFactorSession 두 번째 단계 로그인을 완료하는 데 사용할 수 있는 현재 로그인 흐름의 세션 식별자입니다.

행동 양식

방법 설명
해결SignIn(어설션) 사용자가 두 번째 단계 챌린지를 성공적으로 완료했음을 확인하는 MultiFactorAssertion 을 사용하여 사용자가 두 번째 단계로 로그인을 완료하도록 돕는 도우미 기능입니다.

MultiFactorResolver.hints

현재 세션에 대한 로그인을 완료하는 데 필요한 두 번째 요소에 대한 힌트 목록입니다.

서명:

readonly hints: MultiFactorInfo[];

MultiFactorResolver.session

두 번째 단계 로그인을 완료하는 데 사용할 수 있는 현재 로그인 흐름의 세션 식별자입니다.

서명:

readonly session: MultiFactorSession;

MultiFactorResolver.resolveSignIn()

사용자가 두 번째 단계 챌린지를 성공적으로 완료했음을 확인하는 MultiFactorAssertion 을 사용하여 사용자가 두 번째 단계로 로그인을 완료하도록 돕는 도우미 기능입니다.

서명:

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

매개변수

매개변수 유형 설명
역설 MultiFactorAssertion 로그인을 해결하는 데 사용할 다중 요소 어설션입니다.

보고:

약속< 사용자 자격 증명 >

사용자 자격 증명 개체로 해결되는 약속입니다.

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