Home > @firebase/auth > MultiFactorResolver
MultiFactorResolver interface
The class used to facilitate recovery from MultiFactorError when a user needs to provide a second factor to sign in.
Signature:
export interface MultiFactorResolver
Example
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);
Properties
Property | Type | Description |
---|---|---|
hints | MultiFactorInfo[] | The list of hints for the second factors needed to complete the sign-in for the current session. |
session | MultiFactorSession | The session identifier for the current sign-in flow, which can be used to complete the second factor sign-in. |
Methods
Method | Description |
---|---|
resolveSignIn(assertion) | A helper function to help users complete sign in with a second factor using an MultiFactorAssertion confirming the user successfully completed the second factor challenge. |