@@ -352,36 +352,38 @@ firebase.addAppDelegateMethods = appDelegate => {
352352 if ( userActivity . webpageURL ) {
353353 // check for an email-link-login flow
354354
355- const fAuth = ( typeof ( FIRAuth ) !== "undefined" ) ? FIRAuth . auth ( ) : undefined ;
356- if ( fAuth && fAuth . isSignInWithEmailLink ( userActivity . webpageURL . absoluteString ) ) {
355+ firebase . fAuth = ( typeof ( FIRAuth ) !== "undefined" ) ? FIRAuth . auth ( ) : undefined ;
356+ if ( firebase . fAuth && firebase . fAuth . isSignInWithEmailLink ( userActivity . webpageURL . absoluteString ) ) {
357357 const rememberedEmail = firebase . getRememberedEmailForEmailLinkLogin ( ) ;
358358 if ( rememberedEmail !== undefined ) {
359359
360- if ( fAuth . currentUser ) {
360+ if ( firebase . fAuth . currentUser ) {
361361 const onCompletionLink = ( result : FIRAuthDataResult , error : NSError ) => {
362362 if ( error ) {
363363 // ignore, and complete the email link sign in flow
364- fAuth . signInWithEmailLinkCompletion ( rememberedEmail , userActivity . webpageURL . absoluteString , ( authData : FIRAuthDataResult , error : NSError ) => {
364+ firebase . fAuth . signInWithEmailLinkCompletion ( rememberedEmail , userActivity . webpageURL . absoluteString , ( authData : FIRAuthDataResult , error : NSError ) => {
365365 if ( ! error ) {
366366 firebase . notifyAuthStateListeners ( {
367367 loggedIn : true ,
368368 user : toLoginResult ( authData . user )
369369 } ) ;
370370 }
371+ firebase . fAuth = null ;
371372 } ) ;
372373 } else {
373374 // linking successful, so the user can now log in with either their email address, or however he logged in previously
374375 firebase . notifyAuthStateListeners ( {
375376 loggedIn : true ,
376377 user : toLoginResult ( result . user )
377378 } ) ;
379+ firebase . fAuth = null ;
378380 }
379381 } ;
380382 const fIRAuthCredential = FIREmailAuthProvider . credentialWithEmailLink ( rememberedEmail , userActivity . webpageURL . absoluteString ) ;
381- fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
383+ firebase . fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
382384
383385 } else {
384- fAuth . signInWithEmailLinkCompletion ( rememberedEmail , userActivity . webpageURL . absoluteString , ( authData : FIRAuthDataResult , error : NSError ) => {
386+ firebase . fAuth . signInWithEmailLinkCompletion ( rememberedEmail , userActivity . webpageURL . absoluteString , ( authData : FIRAuthDataResult , error : NSError ) => {
385387 if ( error ) {
386388 console . log ( error . localizedDescription ) ;
387389 } else {
@@ -390,6 +392,7 @@ firebase.addAppDelegateMethods = appDelegate => {
390392 user : toLoginResult ( authData . user )
391393 } ) ;
392394 }
395+ firebase . fAuth = null ;
393396 } ) ;
394397 }
395398 }
@@ -931,18 +934,19 @@ firebase.login = arg => {
931934 user : toLoginResult ( authResult . user )
932935 } ) ;
933936 }
937+ firebase . fAuth = null ;
934938 } ;
935939
936- const fAuth = FIRAuth . auth ( ) ;
937- if ( fAuth === null ) {
940+ firebase . fAuth = FIRAuth . auth ( ) ;
941+ if ( firebase . fAuth === null ) {
938942 reject ( "Run init() first!" ) ;
939943 return ;
940944 }
941945
942946 firebase . moveLoginOptionsToObjects ( arg ) ;
943947
944948 if ( arg . type === firebase . LoginType . ANONYMOUS ) {
945- fAuth . signInAnonymouslyWithCompletion ( onCompletionWithAuthResult ) ;
949+ firebase . fAuth . signInAnonymouslyWithCompletion ( onCompletionWithAuthResult ) ;
946950
947951 } else if ( arg . type === firebase . LoginType . PASSWORD ) {
948952 if ( ! arg . passwordOptions || ! arg . passwordOptions . email || ! arg . passwordOptions . password ) {
@@ -951,21 +955,22 @@ firebase.login = arg => {
951955 }
952956
953957 const fIRAuthCredential = FIREmailAuthProvider . credentialWithEmailPassword ( arg . passwordOptions . email , arg . passwordOptions . password ) ;
954- if ( fAuth . currentUser ) {
958+ if ( firebase . fAuth . currentUser ) {
955959 // link credential, note that you only want to do this if this user doesn't already use fb as an auth provider
956960 const onCompletionLink = ( authData : FIRAuthDataResult , error : NSError ) => {
957961 if ( error ) {
958962 // ignore, as this one was probably already linked, so just return the user
959963 log ( "--- linking error: " + error . localizedDescription ) ;
960- fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
964+ firebase . fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
961965 } else {
962966 onCompletionWithAuthResult ( authData , error ) ;
963967 }
968+ firebase . fAuth = null ;
964969 } ;
965- fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
970+ firebase . fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
966971
967972 } else {
968- fAuth . signInWithEmailPasswordCompletion ( arg . passwordOptions . email , arg . passwordOptions . password , onCompletionWithAuthResult ) ;
973+ firebase . fAuth . signInWithEmailPasswordCompletion ( arg . passwordOptions . email , arg . passwordOptions . password , onCompletionWithAuthResult ) ;
969974 }
970975
971976 } else if ( arg . type === firebase . LoginType . EMAIL_LINK ) {
@@ -989,7 +994,7 @@ firebase.login = arg => {
989994 arg . emailLinkOptions . android ? arg . emailLinkOptions . android . packageName : NSBundle . mainBundle . bundleIdentifier ,
990995 arg . emailLinkOptions . android ? arg . emailLinkOptions . android . installApp || false : false ,
991996 arg . emailLinkOptions . android ? arg . emailLinkOptions . android . minimumVersion || "1" : "1" ) ;
992- fAuth . sendSignInLinkToEmailActionCodeSettingsCompletion (
997+ firebase . fAuth . sendSignInLinkToEmailActionCodeSettingsCompletion (
993998 arg . emailLinkOptions . email ,
994999 firActionCodeSettings ,
9951000 ( error : NSError ) => {
@@ -1023,18 +1028,19 @@ firebase.login = arg => {
10231028 return ;
10241029 }
10251030 const fIRAuthCredential = FIRPhoneAuthProvider . provider ( ) . credentialWithVerificationIDVerificationCode ( verificationID , userResponse ) ;
1026- if ( fAuth . currentUser ) {
1031+ if ( firebase . fAuth . currentUser ) {
10271032 const onCompletionLink = ( authData : FIRAuthDataResult , error : NSError ) => {
10281033 if ( error ) {
10291034 // ignore, as this one was probably already linked, so just return the user
1030- fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1035+ firebase . fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
10311036 } else {
10321037 onCompletionWithAuthResult ( authData , error ) ;
10331038 }
1039+ firebase . fAuth = null ;
10341040 } ;
1035- fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
1041+ firebase . fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
10361042 } else {
1037- fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1043+ firebase . fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
10381044 }
10391045 } , arg . phoneOptions . verificationPrompt ) ;
10401046 } ) ;
@@ -1046,12 +1052,12 @@ firebase.login = arg => {
10461052 }
10471053
10481054 if ( arg . customOptions . token ) {
1049- fAuth . signInWithCustomTokenCompletion ( arg . customOptions . token , onCompletionWithAuthResult ) ;
1055+ firebase . fAuth . signInWithCustomTokenCompletion ( arg . customOptions . token , onCompletionWithAuthResult ) ;
10501056 } else if ( arg . customOptions . tokenProviderFn ) {
10511057 arg . customOptions . tokenProviderFn ( )
10521058 . then (
10531059 token => {
1054- fAuth . signInWithCustomTokenCompletion ( token , onCompletionWithAuthResult ) ;
1060+ firebase . fAuth . signInWithCustomTokenCompletion ( token , onCompletionWithAuthResult ) ;
10551061 } ,
10561062 error => {
10571063 reject ( error ) ;
@@ -1075,21 +1081,22 @@ firebase.login = arg => {
10751081 // headless facebook auth
10761082 // var fIRAuthCredential = FIRFacebookAuthProvider.credentialWithAccessToken(fbSDKLoginManagerLoginResult.token.tokenString);
10771083 const fIRAuthCredential = FIRFacebookAuthProvider . credentialWithAccessToken ( FBSDKAccessToken . currentAccessToken . tokenString ) ;
1078- if ( fAuth . currentUser ) {
1084+ if ( firebase . fAuth . currentUser ) {
10791085 // link credential, note that you only want to do this if this user doesn't already use fb as an auth provider
10801086 const onCompletionLink = ( authData : FIRAuthDataResult , error : NSError ) => {
10811087 if ( error ) {
10821088 // ignore, as this one was probably already linked, so just return the user
10831089 log ( "--- linking error: " + error . localizedDescription ) ;
1084- fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1090+ firebase . fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
10851091 } else {
10861092 onCompletionWithAuthResult ( authData ) ;
10871093 }
1094+ firebase . fAuth = null ;
10881095 } ;
1089- fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
1096+ firebase . fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
10901097
10911098 } else {
1092- fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1099+ firebase . fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
10931100 }
10941101 }
10951102 } ;
@@ -1138,9 +1145,8 @@ firebase.login = arg => {
11381145 appleIDRequest . nonce = sha256Nonce ;
11391146
11401147 const authorizationController = ASAuthorizationController . alloc ( ) . initWithAuthorizationRequests ( [ appleIDRequest ] ) ;
1141- const delegate = ASAuthorizationControllerDelegateImpl . createWithOwnerAndResolveReject ( this as any , resolve , reject ) ;
1142- CFRetain ( delegate ) ;
1143- authorizationController . delegate = delegate ;
1148+ firebase . appleAuthDelegate = ASAuthorizationControllerDelegateImpl . createWithOwnerAndResolveReject ( this as any , resolve , reject ) ;
1149+ authorizationController . delegate = firebase . appleAuthDelegate ;
11441150
11451151 authorizationController . presentationContextProvider = ASAuthorizationControllerPresentationContextProvidingImpl . createWithOwnerAndCallback ( this as any ) ;
11461152
@@ -1164,38 +1170,37 @@ firebase.login = arg => {
11641170 sIn . scopes = arg . googleOptions . scopes ;
11651171 }
11661172
1167- let delegate = GIDSignInDelegateImpl . new ( ) . initWithCallback ( ( user : GIDGoogleUser , error : NSError ) => {
1173+ firebase . googleSignInDelegate = GIDSignInDelegateImpl . new ( ) . initWithCallback ( ( user : GIDGoogleUser , error : NSError ) => {
11681174 if ( error === null ) {
11691175 // Get a Google ID token and Google access token from the GIDAuthentication object and exchange them for a Firebase credential
11701176 firebase . _gIDAuthentication = user . authentication ;
11711177 const fIRAuthCredential = FIRGoogleAuthProvider . credentialWithIDTokenAccessToken ( firebase . _gIDAuthentication . idToken , firebase . _gIDAuthentication . accessToken ) ;
11721178
11731179 // Finally, authenticate with Firebase using the credential
1174- if ( fAuth . currentUser ) {
1180+ if ( firebase . fAuth . currentUser ) {
11751181 // link credential, note that you only want to do this if this user doesn't already use Google as an auth provider
11761182 const onCompletionLink = ( user , error ) => {
11771183 if ( error ) {
11781184 // ignore, as this one was probably already linked, so just return the user
1179- fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1185+ firebase . fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
11801186 } else {
11811187 onCompletionWithAuthResult ( user ) ;
11821188 }
1189+ firebase . fAuth = null ;
11831190 } ;
1184- fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
1191+ firebase . fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
11851192
11861193 } else {
1187- fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1194+ firebase . fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
11881195 }
11891196
11901197 } else {
11911198 reject ( error . localizedDescription ) ;
11921199 }
1193- CFRelease ( delegate ) ;
1194- delegate = undefined ;
1200+ firebase . googleSignInDelegate = null ;
11951201 } ) ;
11961202
1197- CFRetain ( delegate ) ;
1198- sIn . delegate = delegate ;
1203+ sIn . delegate = firebase . googleSignInDelegate ;
11991204 sIn . signIn ( ) ;
12001205 } else {
12011206 reject ( "Unsupported auth type: " + arg . type ) ;
@@ -2624,7 +2629,7 @@ class ASAuthorizationControllerDelegateImpl extends NSObject /* implements ASAut
26242629 if ( ASAuthorizationControllerDelegateImpl . ObjCProtocols . length === 0 && parseInt ( Device . osVersion ) >= 13 ) {
26252630 ASAuthorizationControllerDelegateImpl . ObjCProtocols . push ( ASAuthorizationControllerDelegate ) ;
26262631 }
2627- let delegate = < ASAuthorizationControllerDelegateImpl > ASAuthorizationControllerDelegateImpl . new ( ) ;
2632+ const delegate = < ASAuthorizationControllerDelegateImpl > ASAuthorizationControllerDelegateImpl . new ( ) ;
26282633 delegate . owner = owner ;
26292634 delegate . resolve = resolve ;
26302635 delegate . reject = reject ;
@@ -2667,7 +2672,7 @@ class ASAuthorizationControllerDelegateImpl extends NSObject /* implements ASAut
26672672 user : toLoginResult ( authResult . user )
26682673 } ) ;
26692674 this . resolve ( toLoginResult ( authResult && authResult . user , authResult && authResult . additionalUserInfo ) ) ;
2670- CFRelease ( this ) ;
2675+ firebase . appleAuthDelegate = null ;
26712676 }
26722677 } ) ;
26732678 }
@@ -2688,7 +2693,7 @@ class ASAuthorizationControllerPresentationContextProvidingImpl extends NSObject
26882693 if ( ASAuthorizationControllerPresentationContextProvidingImpl . ObjCProtocols . length === 0 && parseInt ( Device . osVersion ) >= 13 ) {
26892694 ASAuthorizationControllerPresentationContextProvidingImpl . ObjCProtocols . push ( ASAuthorizationControllerPresentationContextProviding ) ;
26902695 }
2691- let delegate = < ASAuthorizationControllerPresentationContextProvidingImpl > ASAuthorizationControllerPresentationContextProvidingImpl . new ( ) ;
2696+ const delegate = < ASAuthorizationControllerPresentationContextProvidingImpl > ASAuthorizationControllerPresentationContextProvidingImpl . new ( ) ;
26922697 delegate . owner = owner ;
26932698 return delegate ;
26942699 }
0 commit comments