MultiFactorResolver interface
Stay organized with collections
Save and categorize content based on your preferences.
The class used to facilitate recovery from MultiFactorError when a user needs to provide a second factor to sign in.
Signature:
export interface MultiFactorResolver
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
MultiFactorResolver.hints
The list of hints for the second factors needed to complete the sign-in for the current session.
Signature:
readonly hints: MultiFactorInfo[];
MultiFactorResolver.session
The session identifier for the current sign-in flow, which can be used to complete the second factor sign-in.
Signature:
readonly session: MultiFactorSession;
MultiFactorResolver.resolveSignIn()
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.
Signature:
resolveSignIn(assertion: MultiFactorAssertion): Promise<UserCredential>;
Parameters
Parameter |
Type |
Description |
assertion |
MultiFactorAssertion |
The multi-factor assertion to resolve sign-in with. |
Returns:
Promise<UserCredential>
The promise that resolves with the user credential object.
Example
const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, verificationCode);
const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
const userCredential = await resolver.resolveSignIn(multiFactorAssertion);
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);
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-01-19 UTC.
[null,null,["Last updated 2024-01-19 UTC."],[],[],null,["# MultiFactorResolver interface\n\nThe class used to facilitate recovery from [MultiFactorError](./auth.multifactorerror.md#multifactorerror_interface) when a user needs to provide a second factor to sign in.\n\n**Signature:** \n\n export interface MultiFactorResolver \n\nProperties\n----------\n\n| Property | Type | Description |\n|---------------------------------------------------------------------|---------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|\n| [hints](./auth.multifactorresolver.md#multifactorresolverhints) | [MultiFactorInfo](./auth.multifactorinfo.md#multifactorinfo_interface)\\[\\] | The list of hints for the second factors needed to complete the sign-in for the current session. |\n| [session](./auth.multifactorresolver.md#multifactorresolversession) | [MultiFactorSession](./auth.multifactorsession.md#multifactorsession_interface) | The session identifier for the current sign-in flow, which can be used to complete the second factor sign-in. |\n\nMethods\n-------\n\n| Method | Description |\n|--------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [resolveSignIn(assertion)](./auth.multifactorresolver.md#multifactorresolverresolvesignin) | A helper function to help users complete sign in with a second factor using an [MultiFactorAssertion](./auth.multifactorassertion.md#multifactorassertion_interface) confirming the user successfully completed the second factor challenge. |\n\nMultiFactorResolver.hints\n-------------------------\n\nThe list of hints for the second factors needed to complete the sign-in for the current session.\n\n**Signature:** \n\n readonly hints: MultiFactorInfo[];\n\nMultiFactorResolver.session\n---------------------------\n\nThe session identifier for the current sign-in flow, which can be used to complete the second factor sign-in.\n\n**Signature:** \n\n readonly session: MultiFactorSession;\n\nMultiFactorResolver.resolveSignIn()\n-----------------------------------\n\nA helper function to help users complete sign in with a second factor using an [MultiFactorAssertion](./auth.multifactorassertion.md#multifactorassertion_interface) confirming the user successfully completed the second factor challenge.\n\n**Signature:** \n\n resolveSignIn(assertion: MultiFactorAssertion): Promise\u003cUserCredential\u003e;\n\n#### Parameters\n\n| Parameter | Type | Description |\n|-----------|---------------------------------------------------------------------------------------|-----------------------------------------------------|\n| assertion | [MultiFactorAssertion](./auth.multifactorassertion.md#multifactorassertion_interface) | The multi-factor assertion to resolve sign-in with. |\n\n**Returns:**\n\nPromise\\\u003c[UserCredential](./auth.usercredential.md#usercredential_interface)\\\u003e\n\nThe promise that resolves with the user credential object.\n\n### Example\n\n const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, verificationCode);\n const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential);\n const userCredential = await resolver.resolveSignIn(multiFactorAssertion);\n\n### Example\n\n let resolver;\n let multiFactorHints;\n\n signInWithEmailAndPassword(auth, email, password)\n .then((result) =\u003e {\n // User signed in. No 2nd factor challenge is needed.\n })\n .catch((error) =\u003e {\n if (error.code == 'auth/multi-factor-auth-required') {\n resolver = getMultiFactorResolver(auth, error);\n // Show UI to let user select second factor.\n multiFactorHints = resolver.hints;\n } else {\n // Handle other errors.\n }\n });\n\n // The enrolled second factors that can be used to complete\n // sign-in are returned in the `MultiFactorResolver.hints` list.\n // UI needs to be presented to allow the user to select a second factor\n // from that list.\n\n const selectedHint = // ; selected from multiFactorHints\n const phoneAuthProvider = new PhoneAuthProvider(auth);\n const phoneInfoOptions = {\n multiFactorHint: selectedHint,\n session: resolver.session\n };\n const verificationId = phoneAuthProvider.verifyPhoneNumber(phoneInfoOptions, appVerifier);\n // Store `verificationId` and show UI to let user enter verification code.\n\n // UI to enter verification code and continue.\n // Continue button click handler\n const phoneAuthCredential = PhoneAuthProvider.credential(verificationId, verificationCode);\n const multiFactorAssertion = PhoneMultiFactorGenerator.assertion(phoneAuthCredential);\n const userCredential = await resolver.resolveSignIn(multiFactorAssertion);"]]