@@ -22,13 +22,12 @@ import {
2222 signInAnonymously as _signInAnonymously ,
2323 signInWithPhoneNumber as _signInWithPhoneNumber ,
2424 ActionCodeSettings ,
25+ ApplicationVerifier ,
2526 AuthProvider ,
2627 ConfirmationResult ,
2728 EmailAuthProvider ,
28- getAuth ,
2929 linkWithCredential ,
3030 PhoneAuthProvider ,
31- RecaptchaVerifier ,
3231 signInWithCredential ,
3332 signInWithRedirect ,
3433 UserCredential ,
@@ -43,7 +42,7 @@ async function handlePendingCredential(ui: FirebaseUIConfiguration, user: UserCr
4342
4443 try {
4544 const pendingCred = JSON . parse ( pendingCredString ) ;
46- ui . setState ( "linking " ) ;
45+ ui . setState ( "pending " ) ;
4746 const result = await linkWithCredential ( user . user , pendingCred ) ;
4847 ui . setState ( "idle" ) ;
4948 window . sessionStorage . removeItem ( "pendingCred" ) ;
@@ -60,19 +59,18 @@ export async function signInWithEmailAndPassword(
6059 password : string
6160) : Promise < UserCredential > {
6261 try {
63- const auth = getAuth ( ui . app ) ;
6462 const credential = EmailAuthProvider . credential ( email , password ) ;
6563
6664 if ( hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
6765 const result = await getBehavior ( ui , "autoUpgradeAnonymousCredential" ) ( ui , credential ) ;
68-
66+
6967 if ( result ) {
7068 return handlePendingCredential ( ui , result ) ;
7169 }
7270 }
7371
74- ui . setState ( "signing-in " ) ;
75- const result = await signInWithCredential ( auth , credential ) ;
72+ ui . setState ( "pending " ) ;
73+ const result = await signInWithCredential ( ui . auth , credential ) ;
7674 return handlePendingCredential ( ui , result ) ;
7775 } catch ( error ) {
7876 handleFirebaseError ( ui , error ) ;
@@ -87,7 +85,6 @@ export async function createUserWithEmailAndPassword(
8785 password : string
8886) : Promise < UserCredential > {
8987 try {
90- const auth = getAuth ( ui . app ) ;
9188 const credential = EmailAuthProvider . credential ( email , password ) ;
9289
9390 if ( hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
@@ -98,8 +95,8 @@ export async function createUserWithEmailAndPassword(
9895 }
9996 }
10097
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 ) ;
103100 return handlePendingCredential ( ui , result ) ;
104101 } catch ( error ) {
105102 handleFirebaseError ( ui , error ) ;
@@ -111,12 +108,11 @@ export async function createUserWithEmailAndPassword(
111108export async function signInWithPhoneNumber (
112109 ui : FirebaseUIConfiguration ,
113110 phoneNumber : string ,
114- recaptchaVerifier : RecaptchaVerifier
111+ appVerifier : ApplicationVerifier
115112) : Promise < ConfirmationResult > {
116113 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 ) ;
120116 } catch ( error ) {
121117 handleFirebaseError ( ui , error ) ;
122118 } finally {
@@ -130,8 +126,7 @@ export async function confirmPhoneNumber(
130126 verificationCode : string
131127) : Promise < UserCredential > {
132128 try {
133- const auth = getAuth ( ui . app ) ;
134- const currentUser = auth . currentUser ;
129+ const currentUser = ui . auth . currentUser ;
135130 const credential = PhoneAuthProvider . credential ( confirmationResult . verificationId , verificationCode ) ;
136131
137132 if ( currentUser ?. isAnonymous && hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
@@ -142,8 +137,8 @@ export async function confirmPhoneNumber(
142137 }
143138 }
144139
145- ui . setState ( "signing-in " ) ;
146- const result = await signInWithCredential ( auth , credential ) ;
140+ ui . setState ( "pending " ) ;
141+ const result = await signInWithCredential ( ui . auth , credential ) ;
147142 return handlePendingCredential ( ui , result ) ;
148143 } catch ( error ) {
149144 handleFirebaseError ( ui , error ) ;
@@ -154,9 +149,8 @@ export async function confirmPhoneNumber(
154149
155150export async function sendPasswordResetEmail ( ui : FirebaseUIConfiguration , email : string ) : Promise < void > {
156151 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 ) ;
160154 } catch ( error ) {
161155 handleFirebaseError ( ui , error ) ;
162156 } finally {
@@ -166,16 +160,15 @@ export async function sendPasswordResetEmail(ui: FirebaseUIConfiguration, email:
166160
167161export async function sendSignInLinkToEmail ( ui : FirebaseUIConfiguration , email : string ) : Promise < void > {
168162 try {
169- const auth = getAuth ( ui . app ) ;
170-
171163 const actionCodeSettings = {
172164 url : window . location . href ,
173165 // TODO(ehesp): Check this...
174166 handleCodeInApp : true ,
175167 } satisfies ActionCodeSettings ;
176168
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")?
179172 window . localStorage . setItem ( "emailForSignIn" , email ) ;
180173 } catch ( error ) {
181174 handleFirebaseError ( ui , error ) ;
@@ -190,7 +183,6 @@ export async function signInWithEmailLink(
190183 link : string
191184) : Promise < UserCredential > {
192185 try {
193- const auth = ui . getAuth ( ) ;
194186 const credential = EmailAuthProvider . credentialWithLink ( email , link ) ;
195187
196188 if ( hasBehavior ( ui , "autoUpgradeAnonymousCredential" ) ) {
@@ -200,8 +192,8 @@ export async function signInWithEmailLink(
200192 }
201193 }
202194
203- ui . setState ( "signing-in " ) ;
204- const result = await signInWithCredential ( auth , credential ) ;
195+ ui . setState ( "pending " ) ;
196+ const result = await signInWithCredential ( ui . auth , credential ) ;
205197 return handlePendingCredential ( ui , result ) ;
206198 } catch ( error ) {
207199 handleFirebaseError ( ui , error ) ;
@@ -212,9 +204,8 @@ export async function signInWithEmailLink(
212204
213205export async function signInAnonymously ( ui : FirebaseUIConfiguration ) : Promise < UserCredential > {
214206 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 ) ;
218209 return handlePendingCredential ( ui , result ) ;
219210 } catch ( error ) {
220211 handleFirebaseError ( ui , error ) ;
@@ -223,18 +214,18 @@ export async function signInAnonymously(ui: FirebaseUIConfiguration): Promise<Us
223214 }
224215}
225216
226- export async function signInWithOAuth ( ui : FirebaseUIConfiguration , provider : AuthProvider ) : Promise < void > {
217+ export async function signInWithProvider ( ui : FirebaseUIConfiguration , provider : AuthProvider ) : Promise < void > {
227218 try {
228- const auth = getAuth ( ui . app ) ;
229-
230219 if ( hasBehavior ( ui , "autoUpgradeAnonymousProvider" ) ) {
231220 await getBehavior ( ui , "autoUpgradeAnonymousProvider" ) ( ui , provider ) ;
232221 // If we get to here, the user is not anonymous, otherwise they
233222 // have been redirected to the provider's sign in page.
234223 }
235224
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 ) ;
238229 // We don't modify state here since the user is redirected.
239230 // If we support popups, we'd need to modify state here.
240231 } catch ( error ) {
@@ -249,17 +240,16 @@ export async function completeEmailLinkSignIn(
249240 currentUrl : string
250241) : Promise < UserCredential | null > {
251242 try {
252- const auth = ui . getAuth ( ) ;
253- if ( ! _isSignInWithEmailLink ( auth , currentUrl ) ) {
243+ if ( ! _isSignInWithEmailLink ( ui . auth , currentUrl ) ) {
254244 return null ;
255245 }
256246
257247 const email = window . localStorage . getItem ( "emailForSignIn" ) ;
258248 if ( ! email ) return null ;
259249
260- ui . setState ( "signing-in " ) ;
250+ ui . setState ( "pending " ) ;
261251 const result = await signInWithEmailLink ( ui , email , currentUrl ) ;
262- ui . setState ( "idle" ) ;
252+ ui . setState ( "idle" ) ; // TODO(ehesp): Do we need this here?
263253 return handlePendingCredential ( ui , result ) ;
264254 } catch ( error ) {
265255 handleFirebaseError ( ui , error ) ;
0 commit comments