MultiFactorResolver interface Stay organized with collections Save and categorize content based on your preferences.
The class used to facilitate recovery fromMultiFactorError when a user needs to provide a second factor to sign in.
Signature:
exportinterfaceMultiFactorResolverProperties
| 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 anMultiFactorAssertion confirming the user successfully completed the second factor challenge. |
MultiFactorResolver.hints
The list of hints for the second factors needed to complete the sign-in for the current session.
Signature:
readonlyhints:MultiFactorInfo[];MultiFactorResolver.session
The session identifier for the current sign-in flow, which can be used to complete the second factor sign-in.
Signature:
readonlysession:MultiFactorSession;MultiFactorResolver.resolveSignIn()
A helper function to help users complete sign in with a second factor using anMultiFactorAssertion 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
constphoneAuthCredential=PhoneAuthProvider.credential(verificationId,verificationCode);constmultiFactorAssertion=PhoneMultiFactorGenerator.assertion(phoneAuthCredential);constuserCredential=awaitresolver.resolveSignIn(multiFactorAssertion);Example
letresolver;letmultiFactorHints;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.constselectedHint=// ; selected from multiFactorHintsconstphoneAuthProvider=newPhoneAuthProvider(auth);constphoneInfoOptions={multiFactorHint:selectedHint,session:resolver.session};constverificationId=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 handlerconstphoneAuthCredential=PhoneAuthProvider.credential(verificationId,verificationCode);constmultiFactorAssertion=PhoneMultiFactorGenerator.assertion(phoneAuthCredential);constuserCredential=awaitresolver.resolveSignIn(multiFactorAssertion);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 2024-01-19 UTC.