這個類別可在使用者需要提供第二重驗證時,協助進行 MultiFactorError 復原。
簽名:
export interface MultiFactorResolver
屬性
屬性 | 類型 | 說明 |
---|---|---|
提示 | 多重要素資訊[] | 完成目前工作階段登入所需的第二項因素提示清單。 |
工作階段 | 多因素工作階段 | 目前登入流程的工作階段 ID,可用於完成第二重驗證登入程序。 |
方法
方法 | 說明 |
---|---|
resolveSignIn(assertion) | 輔助函式可協助使用者透過 MultiFactorAssertion 確認使用者已成功完成第二重驗證,並透過次要驗證完成登入。 |
MultiFactorResolver.hints
完成目前工作階段登入所需的第二項因素提示清單。
簽名:
readonly hints: MultiFactorInfo[];
MultiFactorResolver.session
目前登入流程的工作階段 ID,可用於完成第二重驗證登入程序。
簽名:
readonly session: MultiFactorSession;
MultiFactorResolver.resolveSignIn()
輔助函式可協助使用者透過 MultiFactorAssertion 確認使用者已成功完成第二重驗證,並透過次要驗證完成登入。
簽名:
resolveSignIn(assertion: 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);