@@ -57,13 +57,18 @@ async function handlePendingCredential(_ui: FirebaseUI, user: UserCredential): P
5757 }
5858}
5959
60+ function setPendingState ( ui : FirebaseUI ) {
61+ ui . setRedirectError ( undefined ) ;
62+ ui . setState ( "pending" ) ;
63+ }
64+
6065export async function signInWithEmailAndPassword (
6166 ui : FirebaseUI ,
6267 email : string ,
6368 password : string
6469) : Promise < UserCredential > {
6570 try {
66- ui . setState ( "pending" ) ;
71+ setPendingState ( ui ) ;
6772 const credential = EmailAuthProvider . credential ( email , password ) ;
6873
6974 if ( hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
@@ -90,7 +95,7 @@ export async function createUserWithEmailAndPassword(
9095 displayName ?: string
9196) : Promise < UserCredential > {
9297 try {
93- ui . setState ( "pending" ) ;
98+ setPendingState ( ui ) ;
9499 const credential = EmailAuthProvider . credential ( email , password ) ;
95100
96101 if ( hasBehavior ( ui , "requireDisplayName" ) && ! displayName ) {
@@ -130,7 +135,7 @@ export async function verifyPhoneNumber(
130135 mfaUser ?: MultiFactorUser
131136) : Promise < string > {
132137 try {
133- ui . setState ( "pending" ) ;
138+ setPendingState ( ui ) ;
134139 const provider = new PhoneAuthProvider ( ui . auth ) ;
135140 const session = await mfaUser ?. getSession ( ) ;
136141 return await provider . verifyPhoneNumber (
@@ -155,7 +160,7 @@ export async function confirmPhoneNumber(
155160 verificationCode : string
156161) : Promise < UserCredential > {
157162 try {
158- ui . setState ( "pending" ) ;
163+ setPendingState ( ui ) ;
159164 const currentUser = ui . auth . currentUser ;
160165 const credential = PhoneAuthProvider . credential ( verificationId , verificationCode ) ;
161166
@@ -178,7 +183,7 @@ export async function confirmPhoneNumber(
178183
179184export async function sendPasswordResetEmail ( ui : FirebaseUI , email : string ) : Promise < void > {
180185 try {
181- ui . setState ( "pending" ) ;
186+ setPendingState ( ui ) ;
182187 await _sendPasswordResetEmail ( ui . auth , email ) ;
183188 } catch ( error ) {
184189 handleFirebaseError ( ui , error ) ;
@@ -189,7 +194,7 @@ export async function sendPasswordResetEmail(ui: FirebaseUI, email: string): Pro
189194
190195export async function sendSignInLinkToEmail ( ui : FirebaseUI , email : string ) : Promise < void > {
191196 try {
192- ui . setState ( "pending" ) ;
197+ setPendingState ( ui ) ;
193198 const actionCodeSettings = {
194199 url : window . location . href ,
195200 // TODO(ehesp): Check this...
@@ -213,7 +218,7 @@ export async function signInWithEmailLink(ui: FirebaseUI, email: string, link: s
213218
214219export async function signInWithCredential ( ui : FirebaseUI , credential : AuthCredential ) : Promise < UserCredential > {
215220 try {
216- ui . setState ( "pending" ) ;
221+ setPendingState ( ui ) ;
217222 if ( hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
218223 const userCredential = await getBehavior ( ui , "autoUpgradeAnonymousCredential" ) ( ui , credential ) ;
219224
@@ -235,7 +240,7 @@ export async function signInWithCredential(ui: FirebaseUI, credential: AuthCrede
235240
236241export async function signInAnonymously ( ui : FirebaseUI ) : Promise < UserCredential > {
237242 try {
238- ui . setState ( "pending" ) ;
243+ setPendingState ( ui ) ;
239244 const result = await _signInAnonymously ( ui . auth ) ;
240245 return handlePendingCredential ( ui , result ) ;
241246 } catch ( error ) {
@@ -247,7 +252,7 @@ export async function signInAnonymously(ui: FirebaseUI): Promise<UserCredential>
247252
248253export async function signInWithProvider ( ui : FirebaseUI , provider : AuthProvider ) : Promise < UserCredential | never > {
249254 try {
250- ui . setState ( "pending" ) ;
255+ setPendingState ( ui ) ;
251256 if ( hasBehavior ( ui , "autoUpgradeAnonymousProvider" ) ) {
252257 const credential = await getBehavior ( ui , "autoUpgradeAnonymousProvider" ) ( ui , provider ) ;
253258
@@ -280,7 +285,7 @@ export async function completeEmailLinkSignIn(ui: FirebaseUI, currentUrl: string
280285 const email = window . localStorage . getItem ( "emailForSignIn" ) ;
281286 if ( ! email ) return null ;
282287
283- ui . setState ( "pending" ) ;
288+ setPendingState ( ui ) ;
284289 const result = await signInWithEmailLink ( ui , email , currentUrl ) ;
285290 return handlePendingCredential ( ui , result ) ;
286291 } catch ( error ) {
@@ -317,7 +322,7 @@ export async function enrollWithMultiFactorAssertion(
317322 displayName ?: string
318323) : Promise < void > {
319324 try {
320- ui . setState ( "pending" ) ;
325+ setPendingState ( ui ) ;
321326 await multiFactor ( ui . auth . currentUser ! ) . enroll ( assertion , displayName ) ;
322327 } catch ( error ) {
323328 handleFirebaseError ( ui , error ) ;
@@ -328,7 +333,7 @@ export async function enrollWithMultiFactorAssertion(
328333
329334export async function generateTotpSecret ( ui : FirebaseUI ) : Promise < TotpSecret > {
330335 try {
331- ui . setState ( "pending" ) ;
336+ setPendingState ( ui ) ;
332337 const mfaUser = multiFactor ( ui . auth . currentUser ! ) ;
333338 const session = await mfaUser . getSession ( ) ;
334339 return await TotpMultiFactorGenerator . generateSecret ( session ) ;
0 commit comments