The class used to facilitate recovery from
firebase.auth.MultiFactorError when a user needs to provide a second
factor to sign in.
example
firebase.auth().signInWithEmailAndPassword()
.then(function(result) {
// User signed in. No 2nd factor challenge is needed.
})
.catch(function(error) {
if (error.code == 'auth/multi-factor-auth-required') {
var resolver = error.resolver;
// Show UI to let user select second factor.var 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.var selectedHint = // ; selected from multiFactorHintsvar phoneAuthProvider = new firebase.auth.PhoneAuthProvider();
var phoneInfoOptions = {
multiFactorHint: selectedHint,
session: resolver.session
};
phoneAuthProvider.verifyPhoneNumber(
phoneInfoOptions,
appVerifier
).then(function(verificationId) {
// store verificationID and show UI to let user enter verification code.
});
// UI to enter verification code and continue.// Continue button click handlervar phoneAuthCredential =
firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode);
var multiFactorAssertion =
firebase.auth.PhoneMultiFactorGenerator.assertion(phoneAuthCredential);
resolver.resolveSignIn(multiFactorAssertion)
.then(function(userCredential) {
// User signed in.
});
A helper function to help users complete sign in with a second factor
using an firebase.auth.MultiFactorAssertion confirming the user
successfully completed the second factor challenge.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2022-07-27 UTC."],[],[],null,["- [firebase](/docs/reference/js/v8/firebase).\n- [auth](/docs/reference/js/v8/firebase.auth).\n- MultiFactorResolver \nThe class used to facilitate recovery from\n[firebase.auth.MultiFactorError](/docs/reference/js/v8/firebase.auth.MultiFactorError) when a user needs to provide a second\nfactor to sign in.\n\nexample\n:\n\n firebase.auth().signInWithEmailAndPassword()\n .then(function(result) {\n // User signed in. No 2nd factor challenge is needed.\n })\n .catch(function(error) {\n if (error.code == 'auth/multi-factor-auth-required') {\n var resolver = error.resolver;\n // Show UI to let user select second factor.\n var 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 var selectedHint = // ; selected from multiFactorHints\n var phoneAuthProvider = new firebase.auth.PhoneAuthProvider();\n var phoneInfoOptions = {\n multiFactorHint: selectedHint,\n session: resolver.session\n };\n phoneAuthProvider.verifyPhoneNumber(\n phoneInfoOptions,\n appVerifier\n ).then(function(verificationId) {\n // store verificationID and show UI to let user enter verification code.\n });\n\n // UI to enter verification code and continue.\n // Continue button click handler\n var phoneAuthCredential =\n firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode);\n var multiFactorAssertion =\n firebase.auth.PhoneMultiFactorGenerator.assertion(phoneAuthCredential);\n resolver.resolveSignIn(multiFactorAssertion)\n .then(function(userCredential) {\n // User signed in.\n });\n\n\nIndex\n\nConstructors\n\n- [constructor](/docs/reference/js/v8/firebase.auth.MultiFactorResolver#constructor)\n\nProperties\n\n- [auth](/docs/reference/js/v8/firebase.auth.MultiFactorResolver#auth)\n- [hints](/docs/reference/js/v8/firebase.auth.MultiFactorResolver#hints)\n- [session](/docs/reference/js/v8/firebase.auth.MultiFactorResolver#session)\n\nMethods\n\n- [resolveSignIn](/docs/reference/js/v8/firebase.auth.MultiFactorResolver#resolvesignin)\n\nConstructors\n\nPrivate constructor\n\n- new MultiFactorResolver ( ) : [MultiFactorResolver](/docs/reference/js/v8/firebase.auth.MultiFactorResolver)\n-\n\n Returns [MultiFactorResolver](/docs/reference/js/v8/firebase.auth.MultiFactorResolver)\n\nProperties\n\nauth \nauth: [Auth](/docs/reference/js/v8/firebase.auth.Auth) \nThe Auth instance used to sign in with the first factor.\n\nhints \nhints: [MultiFactorInfo](/docs/reference/js/v8/firebase.auth.MultiFactorInfo)\\[\\] \nThe list of hints for the second factors needed to complete the sign-in\nfor the current session.\n\nsession \nsession: [MultiFactorSession](/docs/reference/js/v8/firebase.auth.MultiFactorSession) \nThe session identifier for the current sign-in flow, which can be used\nto complete the second factor sign-in.\n\nMethods\n\nresolveSignIn\n\n- resolveSignIn ( assertion : [MultiFactorAssertion](/docs/reference/js/v8/firebase.auth.MultiFactorAssertion) ) : Promise \\\u003c [UserCredential](/docs/reference/js/v8/firebase.auth#usercredential) \\\u003e\n- A helper function to help users complete sign in with a second factor\n using an [firebase.auth.MultiFactorAssertion](/docs/reference/js/v8/firebase.auth.MultiFactorAssertion) confirming the user\n successfully completed the second factor challenge.\n\n Error Codes\n\n auth/invalid-verification-code\n : Thrown if the verification code is not valid.\n\n auth/missing-verification-code\n : Thrown if the verification code is missing.\n\n auth/invalid-verification-id\n : Thrown if the credential is a\n [firebase.auth.PhoneAuthProvider.credential](/docs/reference/js/v8/firebase.auth.PhoneAuthProvider#credential) and the verification\n ID of the credential is not valid.\n\n auth/missing-verification-id\n : Thrown if the verification ID is missing.\n\n auth/code-expired\n : Thrown if the verification code has expired.\n\n auth/invalid-multi-factor-session\n : Thrown if the request does not contain a valid proof of first factor\n successful sign-in.\n\n auth/missing-multi-factor-session\n : Thrown if The request is missing proof of first factor successful\n sign-in.\n\n Parameters\n -\n\n assertion: [MultiFactorAssertion](/docs/reference/js/v8/firebase.auth.MultiFactorAssertion) \n The multi-factor assertion to resolve sign-in with.\n\n Returns Promise\\\u003c[UserCredential](/docs/reference/js/v8/firebase.auth#usercredential)\\\u003e\n\nThe promise that resolves with the user credential object."]]
The class used to facilitate recovery from firebase.auth.MultiFactorError when a user needs to provide a second factor to sign in.
firebase.auth().signInWithEmailAndPassword() .then(function(result) { // User signed in. No 2nd factor challenge is needed. }) .catch(function(error) { if (error.code == 'auth/multi-factor-auth-required') { var resolver = error.resolver; // Show UI to let user select second factor. var 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. var selectedHint = // ; selected from multiFactorHints var phoneAuthProvider = new firebase.auth.PhoneAuthProvider(); var phoneInfoOptions = { multiFactorHint: selectedHint, session: resolver.session }; phoneAuthProvider.verifyPhoneNumber( phoneInfoOptions, appVerifier ).then(function(verificationId) { // store verificationID and show UI to let user enter verification code. }); // UI to enter verification code and continue. // Continue button click handler var phoneAuthCredential = firebase.auth.PhoneAuthProvider.credential(verificationId, verificationCode); var multiFactorAssertion = firebase.auth.PhoneMultiFactorGenerator.assertion(phoneAuthCredential); resolver.resolveSignIn(multiFactorAssertion) .then(function(userCredential) { // User signed in. });