@@ -40,15 +40,13 @@ import { hasBehavior, getBehavior } from "./behaviors/index";
40
40
import { FirebaseError } from "firebase/app" ;
41
41
import { getTranslation } from "./translations" ;
42
42
43
- async function handlePendingCredential ( ui : FirebaseUIConfiguration , user : UserCredential ) : Promise < UserCredential > {
43
+ async function handlePendingCredential ( _ui : FirebaseUIConfiguration , user : UserCredential ) : Promise < UserCredential > {
44
44
const pendingCredString = window . sessionStorage . getItem ( "pendingCred" ) ;
45
45
if ( ! pendingCredString ) return user ;
46
46
47
47
try {
48
48
const pendingCred = JSON . parse ( pendingCredString ) ;
49
- ui . setState ( "pending" ) ;
50
49
const result = await linkWithCredential ( user . user , pendingCred ) ;
51
- ui . setState ( "idle" ) ;
52
50
window . sessionStorage . removeItem ( "pendingCred" ) ;
53
51
return result ;
54
52
} catch {
@@ -63,6 +61,7 @@ export async function signInWithEmailAndPassword(
63
61
password : string
64
62
) : Promise < UserCredential > {
65
63
try {
64
+ ui . setState ( "pending" ) ;
66
65
const credential = EmailAuthProvider . credential ( email , password ) ;
67
66
68
67
if ( hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
@@ -73,7 +72,6 @@ export async function signInWithEmailAndPassword(
73
72
}
74
73
}
75
74
76
- ui . setState ( "pending" ) ;
77
75
const result = await _signInWithCredential ( ui . auth , credential ) ;
78
76
return handlePendingCredential ( ui , result ) ;
79
77
} catch ( error ) {
@@ -90,6 +88,7 @@ export async function createUserWithEmailAndPassword(
90
88
displayName ?: string
91
89
) : Promise < UserCredential > {
92
90
try {
91
+ ui . setState ( "pending" ) ;
93
92
const credential = EmailAuthProvider . credential ( email , password ) ;
94
93
95
94
if ( hasBehavior ( ui , "requireDisplayName" ) && ! displayName ) {
@@ -108,7 +107,6 @@ export async function createUserWithEmailAndPassword(
108
107
}
109
108
}
110
109
111
- ui . setState ( "pending" ) ;
112
110
const result = await _createUserWithEmailAndPassword ( ui . auth , email , password ) ;
113
111
114
112
if ( hasBehavior ( ui , "requireDisplayName" ) ) {
@@ -144,6 +142,7 @@ export async function confirmPhoneNumber(
144
142
verificationCode : string
145
143
) : Promise < UserCredential > {
146
144
try {
145
+ ui . setState ( "pending" ) ;
147
146
const currentUser = ui . auth . currentUser ;
148
147
const credential = PhoneAuthProvider . credential ( confirmationResult . verificationId , verificationCode ) ;
149
148
@@ -155,7 +154,6 @@ export async function confirmPhoneNumber(
155
154
}
156
155
}
157
156
158
- ui . setState ( "pending" ) ;
159
157
const result = await _signInWithCredential ( ui . auth , credential ) ;
160
158
return handlePendingCredential ( ui , result ) ;
161
159
} catch ( error ) {
@@ -178,13 +176,13 @@ export async function sendPasswordResetEmail(ui: FirebaseUIConfiguration, email:
178
176
179
177
export async function sendSignInLinkToEmail ( ui : FirebaseUIConfiguration , email : string ) : Promise < void > {
180
178
try {
179
+ ui . setState ( "pending" ) ;
181
180
const actionCodeSettings = {
182
181
url : window . location . href ,
183
182
// TODO(ehesp): Check this...
184
183
handleCodeInApp : true ,
185
184
} satisfies ActionCodeSettings ;
186
185
187
- ui . setState ( "pending" ) ;
188
186
await _sendSignInLinkToEmail ( ui . auth , email , actionCodeSettings ) ;
189
187
// TODO: Should this be a behavior ("storageStrategy")?
190
188
window . localStorage . setItem ( "emailForSignIn" , email ) ;
@@ -209,6 +207,7 @@ export async function signInWithCredential(
209
207
credential : AuthCredential
210
208
) : Promise < UserCredential > {
211
209
try {
210
+ ui . setState ( "pending" ) ;
212
211
if ( hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
213
212
const userCredential = await getBehavior ( ui , "autoUpgradeAnonymousCredential" ) ( ui , credential ) ;
214
213
@@ -219,7 +218,6 @@ export async function signInWithCredential(
219
218
}
220
219
}
221
220
222
- ui . setState ( "pending" ) ;
223
221
const result = await _signInWithCredential ( ui . auth , credential ) ;
224
222
return handlePendingCredential ( ui , result ) ;
225
223
} catch ( error ) {
@@ -246,6 +244,7 @@ export async function signInWithProvider(
246
244
provider : AuthProvider
247
245
) : Promise < UserCredential | never > {
248
246
try {
247
+ ui . setState ( "pending" ) ;
249
248
if ( hasBehavior ( ui , "autoUpgradeAnonymousProvider" ) ) {
250
249
const credential = await getBehavior ( ui , "autoUpgradeAnonymousProvider" ) ( ui , provider ) ;
251
250
@@ -283,7 +282,6 @@ export async function completeEmailLinkSignIn(
283
282
284
283
ui . setState ( "pending" ) ;
285
284
const result = await signInWithEmailLink ( ui , email , currentUrl ) ;
286
- ui . setState ( "idle" ) ; // TODO(ehesp): Do we need this here?
287
285
return handlePendingCredential ( ui , result ) ;
288
286
} catch ( error ) {
289
287
handleFirebaseError ( ui , error ) ;
0 commit comments