@@ -36,15 +36,13 @@ import { FirebaseUIConfiguration } from "./config";
36
36
import { handleFirebaseError } from "./errors" ;
37
37
import { hasBehavior , getBehavior } from "./behaviors/index" ;
38
38
39
- async function handlePendingCredential ( ui : FirebaseUIConfiguration , user : UserCredential ) : Promise < UserCredential > {
39
+ async function handlePendingCredential ( _ui : FirebaseUIConfiguration , user : UserCredential ) : Promise < UserCredential > {
40
40
const pendingCredString = window . sessionStorage . getItem ( "pendingCred" ) ;
41
41
if ( ! pendingCredString ) return user ;
42
42
43
43
try {
44
44
const pendingCred = JSON . parse ( pendingCredString ) ;
45
- ui . setState ( "pending" ) ;
46
45
const result = await linkWithCredential ( user . user , pendingCred ) ;
47
- ui . setState ( "idle" ) ;
48
46
window . sessionStorage . removeItem ( "pendingCred" ) ;
49
47
return result ;
50
48
} catch {
@@ -59,6 +57,7 @@ export async function signInWithEmailAndPassword(
59
57
password : string
60
58
) : Promise < UserCredential > {
61
59
try {
60
+ ui . setState ( "pending" ) ;
62
61
const credential = EmailAuthProvider . credential ( email , password ) ;
63
62
64
63
if ( hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
@@ -69,7 +68,6 @@ export async function signInWithEmailAndPassword(
69
68
}
70
69
}
71
70
72
- ui . setState ( "pending" ) ;
73
71
const result = await _signInWithCredential ( ui . auth , credential ) ;
74
72
return handlePendingCredential ( ui , result ) ;
75
73
} catch ( error ) {
@@ -85,6 +83,7 @@ export async function createUserWithEmailAndPassword(
85
83
password : string
86
84
) : Promise < UserCredential > {
87
85
try {
86
+ ui . setState ( "pending" ) ;
88
87
const credential = EmailAuthProvider . credential ( email , password ) ;
89
88
90
89
if ( hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
@@ -95,7 +94,6 @@ export async function createUserWithEmailAndPassword(
95
94
}
96
95
}
97
96
98
- ui . setState ( "pending" ) ;
99
97
const result = await _createUserWithEmailAndPassword ( ui . auth , email , password ) ;
100
98
return handlePendingCredential ( ui , result ) ;
101
99
} catch ( error ) {
@@ -126,6 +124,7 @@ export async function confirmPhoneNumber(
126
124
verificationCode : string
127
125
) : Promise < UserCredential > {
128
126
try {
127
+ ui . setState ( "pending" ) ;
129
128
const currentUser = ui . auth . currentUser ;
130
129
const credential = PhoneAuthProvider . credential ( confirmationResult . verificationId , verificationCode ) ;
131
130
@@ -137,7 +136,6 @@ export async function confirmPhoneNumber(
137
136
}
138
137
}
139
138
140
- ui . setState ( "pending" ) ;
141
139
const result = await _signInWithCredential ( ui . auth , credential ) ;
142
140
return handlePendingCredential ( ui , result ) ;
143
141
} catch ( error ) {
@@ -160,13 +158,13 @@ export async function sendPasswordResetEmail(ui: FirebaseUIConfiguration, email:
160
158
161
159
export async function sendSignInLinkToEmail ( ui : FirebaseUIConfiguration , email : string ) : Promise < void > {
162
160
try {
161
+ ui . setState ( "pending" ) ;
163
162
const actionCodeSettings = {
164
163
url : window . location . href ,
165
164
// TODO(ehesp): Check this...
166
165
handleCodeInApp : true ,
167
166
} satisfies ActionCodeSettings ;
168
167
169
- ui . setState ( "pending" ) ;
170
168
await _sendSignInLinkToEmail ( ui . auth , email , actionCodeSettings ) ;
171
169
// TODO: Should this be a behavior ("storageStrategy")?
172
170
window . localStorage . setItem ( "emailForSignIn" , email ) ;
@@ -191,6 +189,7 @@ export async function signInWithCredential(
191
189
credential : AuthCredential
192
190
) : Promise < UserCredential > {
193
191
try {
192
+ ui . setState ( "pending" ) ;
194
193
if ( hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
195
194
const userCredential = await getBehavior ( ui , "autoUpgradeAnonymousCredential" ) ( ui , credential ) ;
196
195
@@ -201,7 +200,6 @@ export async function signInWithCredential(
201
200
}
202
201
}
203
202
204
- ui . setState ( "pending" ) ;
205
203
const result = await _signInWithCredential ( ui . auth , credential ) ;
206
204
return handlePendingCredential ( ui , result ) ;
207
205
} catch ( error ) {
@@ -228,6 +226,7 @@ export async function signInWithProvider(
228
226
provider : AuthProvider
229
227
) : Promise < UserCredential | never > {
230
228
try {
229
+ ui . setState ( "pending" ) ;
231
230
if ( hasBehavior ( ui , "autoUpgradeAnonymousProvider" ) ) {
232
231
const credential = await getBehavior ( ui , "autoUpgradeAnonymousProvider" ) ( ui , provider ) ;
233
232
@@ -265,7 +264,6 @@ export async function completeEmailLinkSignIn(
265
264
266
265
ui . setState ( "pending" ) ;
267
266
const result = await signInWithEmailLink ( ui , email , currentUrl ) ;
268
- ui . setState ( "idle" ) ; // TODO(ehesp): Do we need this here?
269
267
return handlePendingCredential ( ui , result ) ;
270
268
} catch ( error ) {
271
269
handleFirebaseError ( ui , error ) ;
0 commit comments