@@ -22,13 +22,12 @@ import {
22
22
signInAnonymously as _signInAnonymously ,
23
23
signInWithPhoneNumber as _signInWithPhoneNumber ,
24
24
ActionCodeSettings ,
25
+ ApplicationVerifier ,
25
26
AuthProvider ,
26
27
ConfirmationResult ,
27
28
EmailAuthProvider ,
28
- getAuth ,
29
29
linkWithCredential ,
30
30
PhoneAuthProvider ,
31
- RecaptchaVerifier ,
32
31
signInWithCredential ,
33
32
signInWithRedirect ,
34
33
UserCredential ,
@@ -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,19 +59,18 @@ 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" ) ) {
67
65
const result = await getBehavior ( ui , "autoUpgradeAnonymousCredential" ) ( ui , credential ) ;
68
-
66
+
69
67
if ( result ) {
70
68
return handlePendingCredential ( ui , result ) ;
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 ) ;
@@ -111,12 +108,11 @@ export async function createUserWithEmailAndPassword(
111
108
export async function signInWithPhoneNumber (
112
109
ui : FirebaseUIConfiguration ,
113
110
phoneNumber : string ,
114
- recaptchaVerifier : RecaptchaVerifier
111
+ appVerifier : ApplicationVerifier
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 , appVerifier ) ;
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,15 @@ 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 ) ;
171
+ // TODO: Should this be a behavior ("storageStrategy")?
179
172
window . localStorage . setItem ( "emailForSignIn" , email ) ;
180
173
} catch ( error ) {
181
174
handleFirebaseError ( ui , error ) ;
@@ -190,7 +183,6 @@ export async function signInWithEmailLink(
190
183
link : string
191
184
) : Promise < UserCredential > {
192
185
try {
193
- const auth = ui . getAuth ( ) ;
194
186
const credential = EmailAuthProvider . credentialWithLink ( email , link ) ;
195
187
196
188
if ( hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
@@ -200,8 +192,8 @@ export async function signInWithEmailLink(
200
192
}
201
193
}
202
194
203
- ui . setState ( "signing-in " ) ;
204
- const result = await signInWithCredential ( auth , credential ) ;
195
+ ui . setState ( "pending " ) ;
196
+ const result = await signInWithCredential ( ui . auth , credential ) ;
205
197
return handlePendingCredential ( ui , result ) ;
206
198
} catch ( error ) {
207
199
handleFirebaseError ( ui , error ) ;
@@ -212,9 +204,8 @@ export async function signInWithEmailLink(
212
204
213
205
export async function signInAnonymously ( ui : FirebaseUIConfiguration ) : Promise < UserCredential > {
214
206
try {
215
- const auth = getAuth ( ui . app ) ;
216
- ui . setState ( "signing-in" ) ;
217
- const result = await _signInAnonymously ( auth ) ;
207
+ ui . setState ( "pending" ) ;
208
+ const result = await _signInAnonymously ( ui . auth ) ;
218
209
return handlePendingCredential ( ui , result ) ;
219
210
} catch ( error ) {
220
211
handleFirebaseError ( ui , error ) ;
@@ -223,18 +214,18 @@ export async function signInAnonymously(ui: FirebaseUIConfiguration): Promise<Us
223
214
}
224
215
}
225
216
226
- export async function signInWithOAuth ( ui : FirebaseUIConfiguration , provider : AuthProvider ) : Promise < void > {
217
+ export async function signInWithProvider ( ui : FirebaseUIConfiguration , provider : AuthProvider ) : Promise < void > {
227
218
try {
228
- const auth = getAuth ( ui . app ) ;
229
-
230
219
if ( hasBehavior ( ui , "autoUpgradeAnonymousProvider" ) ) {
231
220
await getBehavior ( ui , "autoUpgradeAnonymousProvider" ) ( ui , provider ) ;
232
221
// If we get to here, the user is not anonymous, otherwise they
233
222
// have been redirected to the provider's sign in page.
234
223
}
235
224
236
- ui . setState ( "signing-in" ) ;
237
- await signInWithRedirect ( auth , provider ) ;
225
+ ui . setState ( "pending" ) ;
226
+
227
+ // TODO(ehesp): Handle popup or redirect based on behavior
228
+ await signInWithRedirect ( ui . auth , provider ) ;
238
229
// We don't modify state here since the user is redirected.
239
230
// If we support popups, we'd need to modify state here.
240
231
} catch ( error ) {
@@ -249,17 +240,16 @@ export async function completeEmailLinkSignIn(
249
240
currentUrl : string
250
241
) : Promise < UserCredential | null > {
251
242
try {
252
- const auth = ui . getAuth ( ) ;
253
- if ( ! _isSignInWithEmailLink ( auth , currentUrl ) ) {
243
+ if ( ! _isSignInWithEmailLink ( ui . auth , currentUrl ) ) {
254
244
return null ;
255
245
}
256
246
257
247
const email = window . localStorage . getItem ( "emailForSignIn" ) ;
258
248
if ( ! email ) return null ;
259
249
260
- ui . setState ( "signing-in " ) ;
250
+ ui . setState ( "pending " ) ;
261
251
const result = await signInWithEmailLink ( ui , email , currentUrl ) ;
262
- ui . setState ( "idle" ) ;
252
+ ui . setState ( "idle" ) ; // TODO(ehesp): Do we need this here?
263
253
return handlePendingCredential ( ui , result ) ;
264
254
} catch ( error ) {
265
255
handleFirebaseError ( ui , error ) ;
0 commit comments