@@ -25,7 +25,6 @@ import {
25
25
AuthProvider ,
26
26
ConfirmationResult ,
27
27
EmailAuthProvider ,
28
- getAuth ,
29
28
linkWithCredential ,
30
29
PhoneAuthProvider ,
31
30
RecaptchaVerifier ,
@@ -43,7 +42,7 @@ async function handlePendingCredential(ui: FirebaseUIConfiguration, user: UserCr
43
42
44
43
try {
45
44
const pendingCred = JSON . parse ( pendingCredString ) ;
46
- ui . setState ( "linking " ) ;
45
+ ui . setState ( "pending " ) ;
47
46
const result = await linkWithCredential ( user . user , pendingCred ) ;
48
47
ui . setState ( "idle" ) ;
49
48
window . sessionStorage . removeItem ( "pendingCred" ) ;
@@ -60,7 +59,6 @@ export async function signInWithEmailAndPassword(
60
59
password : string
61
60
) : Promise < UserCredential > {
62
61
try {
63
- const auth = getAuth ( ui . app ) ;
64
62
const credential = EmailAuthProvider . credential ( email , password ) ;
65
63
66
64
if ( hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
@@ -71,8 +69,8 @@ export async function signInWithEmailAndPassword(
71
69
}
72
70
}
73
71
74
- ui . setState ( "signing-in " ) ;
75
- const result = await signInWithCredential ( auth , credential ) ;
72
+ ui . setState ( "pending " ) ;
73
+ const result = await signInWithCredential ( ui . auth , credential ) ;
76
74
return handlePendingCredential ( ui , result ) ;
77
75
} catch ( error ) {
78
76
handleFirebaseError ( ui , error ) ;
@@ -87,7 +85,6 @@ export async function createUserWithEmailAndPassword(
87
85
password : string
88
86
) : Promise < UserCredential > {
89
87
try {
90
- const auth = getAuth ( ui . app ) ;
91
88
const credential = EmailAuthProvider . credential ( email , password ) ;
92
89
93
90
if ( hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
@@ -98,8 +95,8 @@ export async function createUserWithEmailAndPassword(
98
95
}
99
96
}
100
97
101
- ui . setState ( "creating-user " ) ;
102
- const result = await _createUserWithEmailAndPassword ( auth , email , password ) ;
98
+ ui . setState ( "pending " ) ;
99
+ const result = await _createUserWithEmailAndPassword ( ui . auth , email , password ) ;
103
100
return handlePendingCredential ( ui , result ) ;
104
101
} catch ( error ) {
105
102
handleFirebaseError ( ui , error ) ;
@@ -114,9 +111,8 @@ export async function signInWithPhoneNumber(
114
111
recaptchaVerifier : RecaptchaVerifier
115
112
) : Promise < ConfirmationResult > {
116
113
try {
117
- const auth = getAuth ( ui . app ) ;
118
- ui . setState ( "signing-in" ) ;
119
- return await _signInWithPhoneNumber ( auth , phoneNumber , recaptchaVerifier ) ;
114
+ ui . setState ( "pending" ) ;
115
+ return await _signInWithPhoneNumber ( ui . auth , phoneNumber , recaptchaVerifier ) ;
120
116
} catch ( error ) {
121
117
handleFirebaseError ( ui , error ) ;
122
118
} finally {
@@ -130,8 +126,7 @@ export async function confirmPhoneNumber(
130
126
verificationCode : string
131
127
) : Promise < UserCredential > {
132
128
try {
133
- const auth = getAuth ( ui . app ) ;
134
- const currentUser = auth . currentUser ;
129
+ const currentUser = ui . auth . currentUser ;
135
130
const credential = PhoneAuthProvider . credential ( confirmationResult . verificationId , verificationCode ) ;
136
131
137
132
if ( currentUser ?. isAnonymous && hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
@@ -142,8 +137,8 @@ export async function confirmPhoneNumber(
142
137
}
143
138
}
144
139
145
- ui . setState ( "signing-in " ) ;
146
- const result = await signInWithCredential ( auth , credential ) ;
140
+ ui . setState ( "pending " ) ;
141
+ const result = await signInWithCredential ( ui . auth , credential ) ;
147
142
return handlePendingCredential ( ui , result ) ;
148
143
} catch ( error ) {
149
144
handleFirebaseError ( ui , error ) ;
@@ -154,9 +149,8 @@ export async function confirmPhoneNumber(
154
149
155
150
export async function sendPasswordResetEmail ( ui : FirebaseUIConfiguration , email : string ) : Promise < void > {
156
151
try {
157
- const auth = getAuth ( ui . app ) ;
158
- ui . setState ( "sending-password-reset-email" ) ;
159
- await _sendPasswordResetEmail ( auth , email ) ;
152
+ ui . setState ( "pending" ) ;
153
+ await _sendPasswordResetEmail ( ui . auth , email ) ;
160
154
} catch ( error ) {
161
155
handleFirebaseError ( ui , error ) ;
162
156
} finally {
@@ -166,16 +160,14 @@ export async function sendPasswordResetEmail(ui: FirebaseUIConfiguration, email:
166
160
167
161
export async function sendSignInLinkToEmail ( ui : FirebaseUIConfiguration , email : string ) : Promise < void > {
168
162
try {
169
- const auth = getAuth ( ui . app ) ;
170
-
171
163
const actionCodeSettings = {
172
164
url : window . location . href ,
173
165
// TODO(ehesp): Check this...
174
166
handleCodeInApp : true ,
175
167
} satisfies ActionCodeSettings ;
176
168
177
- ui . setState ( "sending-sign-in-link-to-email " ) ;
178
- await _sendSignInLinkToEmail ( auth , email , actionCodeSettings ) ;
169
+ ui . setState ( "pending " ) ;
170
+ await _sendSignInLinkToEmail ( ui . auth , email , actionCodeSettings ) ;
179
171
window . localStorage . setItem ( "emailForSignIn" , email ) ;
180
172
} catch ( error ) {
181
173
handleFirebaseError ( ui , error ) ;
@@ -190,7 +182,6 @@ export async function signInWithEmailLink(
190
182
link : string
191
183
) : Promise < UserCredential > {
192
184
try {
193
- const auth = ui . getAuth ( ) ;
194
185
const credential = EmailAuthProvider . credentialWithLink ( email , link ) ;
195
186
196
187
if ( hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
@@ -200,8 +191,8 @@ export async function signInWithEmailLink(
200
191
}
201
192
}
202
193
203
- ui . setState ( "signing-in " ) ;
204
- const result = await signInWithCredential ( auth , credential ) ;
194
+ ui . setState ( "pending " ) ;
195
+ const result = await signInWithCredential ( ui . auth , credential ) ;
205
196
return handlePendingCredential ( ui , result ) ;
206
197
} catch ( error ) {
207
198
handleFirebaseError ( ui , error ) ;
@@ -212,9 +203,8 @@ export async function signInWithEmailLink(
212
203
213
204
export async function signInAnonymously ( ui : FirebaseUIConfiguration ) : Promise < UserCredential > {
214
205
try {
215
- const auth = getAuth ( ui . app ) ;
216
- ui . setState ( "signing-in" ) ;
217
- const result = await _signInAnonymously ( auth ) ;
206
+ ui . setState ( "pending" ) ;
207
+ const result = await _signInAnonymously ( ui . auth ) ;
218
208
return handlePendingCredential ( ui , result ) ;
219
209
} catch ( error ) {
220
210
handleFirebaseError ( ui , error ) ;
@@ -225,16 +215,14 @@ export async function signInAnonymously(ui: FirebaseUIConfiguration): Promise<Us
225
215
226
216
export async function signInWithOAuth ( ui : FirebaseUIConfiguration , provider : AuthProvider ) : Promise < void > {
227
217
try {
228
- const auth = getAuth ( ui . app ) ;
229
-
230
218
if ( hasBehavior ( ui , "autoUpgradeAnonymousProvider" ) ) {
231
219
await getBehavior ( ui , "autoUpgradeAnonymousProvider" ) ( ui , provider ) ;
232
220
// If we get to here, the user is not anonymous, otherwise they
233
221
// have been redirected to the provider's sign in page.
234
222
}
235
223
236
- ui . setState ( "signing-in " ) ;
237
- await signInWithRedirect ( auth , provider ) ;
224
+ ui . setState ( "pending " ) ;
225
+ await signInWithRedirect ( ui . auth , provider ) ;
238
226
// We don't modify state here since the user is redirected.
239
227
// If we support popups, we'd need to modify state here.
240
228
} catch ( error ) {
@@ -249,15 +237,14 @@ export async function completeEmailLinkSignIn(
249
237
currentUrl : string
250
238
) : Promise < UserCredential | null > {
251
239
try {
252
- const auth = ui . getAuth ( ) ;
253
- if ( ! _isSignInWithEmailLink ( auth , currentUrl ) ) {
240
+ if ( ! _isSignInWithEmailLink ( ui . auth , currentUrl ) ) {
254
241
return null ;
255
242
}
256
243
257
244
const email = window . localStorage . getItem ( "emailForSignIn" ) ;
258
245
if ( ! email ) return null ;
259
246
260
- ui . setState ( "signing-in " ) ;
247
+ ui . setState ( "pending " ) ;
261
248
const result = await signInWithEmailLink ( ui , email , currentUrl ) ;
262
249
ui . setState ( "idle" ) ;
263
250
return handlePendingCredential ( ui , result ) ;
0 commit comments