The class used to facilitate recovery fromfirebase.auth.MultiFactorError when a user needs to provide a secondfactor 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. });
Index
Constructors
Private constructor
- new
Multi Factor Resolver():MultiFactorResolver ReturnsMultiFactorResolver
Properties
auth
The Auth instance used to sign in with the first factor.
hints
The list of hints for the second factors needed to complete the sign-infor the current session.
session
The session identifier for the current sign-in flow, which can be usedto complete the second factor sign-in.
Methods
resolveSignIn
- resolve
Sign In(assertion: MultiFactorAssertion):Promise<UserCredential> A helper function to help users complete sign in with a second factorusing anfirebase.auth.MultiFactorAssertion confirming the usersuccessfully completed the second factor challenge.
Error Codes
- auth/invalid-verification-code
- Thrown if the verification code is not valid.
- auth/missing-verification-code
- Thrown if the verification code is missing.
- auth/invalid-verification-id
- Thrown if the credential is afirebase.auth.PhoneAuthProvider.credential and the verificationID of the credential is not valid.
- auth/missing-verification-id
- Thrown if the verification ID is missing.
- auth/code-expired
- Thrown if the verification code has expired.
- auth/invalid-multi-factor-session
- Thrown if the request does not contain a valid proof of first factorsuccessful sign-in.
- auth/missing-multi-factor-session
- Thrown if The request is missing proof of first factor successfulsign-in.
Parameters
assertion:MultiFactorAssertion
The multi-factor assertion to resolve sign-in with.
ReturnsPromise<UserCredential>
The promise that resolves with the user credential object.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-07-27 UTC.