MultiFactorResolver interface

사용자가 로그인할 때 두 번째 단계를 제공해야 하는 경우 MultiFactorError로부터의 복구를 용이하게 하는 데 사용되는 클래스입니다.

서명:

export interface MultiFactorResolver 

속성

속성 유형 설명
힌트 MultiFactorInfo[] 현재 세션에서 로그인을 완료하는 데 필요한 2단계에 대한 힌트 목록입니다.
session MultiFactorSession 현재 로그인 흐름의 세션 식별자로, 2단계 로그인을 완료하는 데 사용할 수 있습니다.

메소드

메서드 설명
resolveSignIn(assertion) 사용자가 2단계 인증 챌린지를 성공적으로 완료했음을 확인하는 MultiFactorAssertion을 사용하여 2단계 로그인을 완료하도록 도와주는 도우미 함수입니다.

MultiFactorResolver.hints

현재 세션에서 로그인을 완료하는 데 필요한 2단계에 대한 힌트 목록입니다.

서명:

readonly hints: MultiFactorInfo[];

MultiFactorResolver.session

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

서명:

readonly session: MultiFactorSession;

MultiFactorResolver.resolveSignIn()

사용자가 2단계 인증 챌린지를 성공적으로 완료했음을 확인하는 MultiFactorAssertion을 사용하여 2단계 로그인을 완료하도록 도와주는 도우미 함수입니다.

서명:

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

매개변수

매개변수 유형 설명
어설션 MultiFactorAssertion 로그인을 확인하는 다단계 어설션입니다.

반환:

프로미스<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);