@@ -352,36 +352,38 @@ firebase.addAppDelegateMethods = appDelegate => {
352
352
if ( userActivity . webpageURL ) {
353
353
// check for an email-link-login flow
354
354
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 ) ) {
357
357
const rememberedEmail = firebase . getRememberedEmailForEmailLinkLogin ( ) ;
358
358
if ( rememberedEmail !== undefined ) {
359
359
360
- if ( fAuth . currentUser ) {
360
+ if ( firebase . fAuth . currentUser ) {
361
361
const onCompletionLink = ( result : FIRAuthDataResult , error : NSError ) => {
362
362
if ( error ) {
363
363
// 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 ) => {
365
365
if ( ! error ) {
366
366
firebase . notifyAuthStateListeners ( {
367
367
loggedIn : true ,
368
368
user : toLoginResult ( authData . user )
369
369
} ) ;
370
370
}
371
+ firebase . fAuth = null ;
371
372
} ) ;
372
373
} else {
373
374
// linking successful, so the user can now log in with either their email address, or however he logged in previously
374
375
firebase . notifyAuthStateListeners ( {
375
376
loggedIn : true ,
376
377
user : toLoginResult ( result . user )
377
378
} ) ;
379
+ firebase . fAuth = null ;
378
380
}
379
381
} ;
380
382
const fIRAuthCredential = FIREmailAuthProvider . credentialWithEmailLink ( rememberedEmail , userActivity . webpageURL . absoluteString ) ;
381
- fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
383
+ firebase . fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
382
384
383
385
} else {
384
- fAuth . signInWithEmailLinkCompletion ( rememberedEmail , userActivity . webpageURL . absoluteString , ( authData : FIRAuthDataResult , error : NSError ) => {
386
+ firebase . fAuth . signInWithEmailLinkCompletion ( rememberedEmail , userActivity . webpageURL . absoluteString , ( authData : FIRAuthDataResult , error : NSError ) => {
385
387
if ( error ) {
386
388
console . log ( error . localizedDescription ) ;
387
389
} else {
@@ -390,6 +392,7 @@ firebase.addAppDelegateMethods = appDelegate => {
390
392
user : toLoginResult ( authData . user )
391
393
} ) ;
392
394
}
395
+ firebase . fAuth = null ;
393
396
} ) ;
394
397
}
395
398
}
@@ -931,18 +934,19 @@ firebase.login = arg => {
931
934
user : toLoginResult ( authResult . user )
932
935
} ) ;
933
936
}
937
+ firebase . fAuth = null ;
934
938
} ;
935
939
936
- const fAuth = FIRAuth . auth ( ) ;
937
- if ( fAuth === null ) {
940
+ firebase . fAuth = FIRAuth . auth ( ) ;
941
+ if ( firebase . fAuth === null ) {
938
942
reject ( "Run init() first!" ) ;
939
943
return ;
940
944
}
941
945
942
946
firebase . moveLoginOptionsToObjects ( arg ) ;
943
947
944
948
if ( arg . type === firebase . LoginType . ANONYMOUS ) {
945
- fAuth . signInAnonymouslyWithCompletion ( onCompletionWithAuthResult ) ;
949
+ firebase . fAuth . signInAnonymouslyWithCompletion ( onCompletionWithAuthResult ) ;
946
950
947
951
} else if ( arg . type === firebase . LoginType . PASSWORD ) {
948
952
if ( ! arg . passwordOptions || ! arg . passwordOptions . email || ! arg . passwordOptions . password ) {
@@ -951,21 +955,22 @@ firebase.login = arg => {
951
955
}
952
956
953
957
const fIRAuthCredential = FIREmailAuthProvider . credentialWithEmailPassword ( arg . passwordOptions . email , arg . passwordOptions . password ) ;
954
- if ( fAuth . currentUser ) {
958
+ if ( firebase . fAuth . currentUser ) {
955
959
// link credential, note that you only want to do this if this user doesn't already use fb as an auth provider
956
960
const onCompletionLink = ( authData : FIRAuthDataResult , error : NSError ) => {
957
961
if ( error ) {
958
962
// ignore, as this one was probably already linked, so just return the user
959
963
log ( "--- linking error: " + error . localizedDescription ) ;
960
- fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
964
+ firebase . fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
961
965
} else {
962
966
onCompletionWithAuthResult ( authData , error ) ;
963
967
}
968
+ firebase . fAuth = null ;
964
969
} ;
965
- fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
970
+ firebase . fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
966
971
967
972
} else {
968
- fAuth . signInWithEmailPasswordCompletion ( arg . passwordOptions . email , arg . passwordOptions . password , onCompletionWithAuthResult ) ;
973
+ firebase . fAuth . signInWithEmailPasswordCompletion ( arg . passwordOptions . email , arg . passwordOptions . password , onCompletionWithAuthResult ) ;
969
974
}
970
975
971
976
} else if ( arg . type === firebase . LoginType . EMAIL_LINK ) {
@@ -989,7 +994,7 @@ firebase.login = arg => {
989
994
arg . emailLinkOptions . android ? arg . emailLinkOptions . android . packageName : NSBundle . mainBundle . bundleIdentifier ,
990
995
arg . emailLinkOptions . android ? arg . emailLinkOptions . android . installApp || false : false ,
991
996
arg . emailLinkOptions . android ? arg . emailLinkOptions . android . minimumVersion || "1" : "1" ) ;
992
- fAuth . sendSignInLinkToEmailActionCodeSettingsCompletion (
997
+ firebase . fAuth . sendSignInLinkToEmailActionCodeSettingsCompletion (
993
998
arg . emailLinkOptions . email ,
994
999
firActionCodeSettings ,
995
1000
( error : NSError ) => {
@@ -1023,18 +1028,19 @@ firebase.login = arg => {
1023
1028
return ;
1024
1029
}
1025
1030
const fIRAuthCredential = FIRPhoneAuthProvider . provider ( ) . credentialWithVerificationIDVerificationCode ( verificationID , userResponse ) ;
1026
- if ( fAuth . currentUser ) {
1031
+ if ( firebase . fAuth . currentUser ) {
1027
1032
const onCompletionLink = ( authData : FIRAuthDataResult , error : NSError ) => {
1028
1033
if ( error ) {
1029
1034
// ignore, as this one was probably already linked, so just return the user
1030
- fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1035
+ firebase . fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1031
1036
} else {
1032
1037
onCompletionWithAuthResult ( authData , error ) ;
1033
1038
}
1039
+ firebase . fAuth = null ;
1034
1040
} ;
1035
- fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
1041
+ firebase . fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
1036
1042
} else {
1037
- fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1043
+ firebase . fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1038
1044
}
1039
1045
} , arg . phoneOptions . verificationPrompt ) ;
1040
1046
} ) ;
@@ -1046,12 +1052,12 @@ firebase.login = arg => {
1046
1052
}
1047
1053
1048
1054
if ( arg . customOptions . token ) {
1049
- fAuth . signInWithCustomTokenCompletion ( arg . customOptions . token , onCompletionWithAuthResult ) ;
1055
+ firebase . fAuth . signInWithCustomTokenCompletion ( arg . customOptions . token , onCompletionWithAuthResult ) ;
1050
1056
} else if ( arg . customOptions . tokenProviderFn ) {
1051
1057
arg . customOptions . tokenProviderFn ( )
1052
1058
. then (
1053
1059
token => {
1054
- fAuth . signInWithCustomTokenCompletion ( token , onCompletionWithAuthResult ) ;
1060
+ firebase . fAuth . signInWithCustomTokenCompletion ( token , onCompletionWithAuthResult ) ;
1055
1061
} ,
1056
1062
error => {
1057
1063
reject ( error ) ;
@@ -1075,21 +1081,22 @@ firebase.login = arg => {
1075
1081
// headless facebook auth
1076
1082
// var fIRAuthCredential = FIRFacebookAuthProvider.credentialWithAccessToken(fbSDKLoginManagerLoginResult.token.tokenString);
1077
1083
const fIRAuthCredential = FIRFacebookAuthProvider . credentialWithAccessToken ( FBSDKAccessToken . currentAccessToken . tokenString ) ;
1078
- if ( fAuth . currentUser ) {
1084
+ if ( firebase . fAuth . currentUser ) {
1079
1085
// link credential, note that you only want to do this if this user doesn't already use fb as an auth provider
1080
1086
const onCompletionLink = ( authData : FIRAuthDataResult , error : NSError ) => {
1081
1087
if ( error ) {
1082
1088
// ignore, as this one was probably already linked, so just return the user
1083
1089
log ( "--- linking error: " + error . localizedDescription ) ;
1084
- fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1090
+ firebase . fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1085
1091
} else {
1086
1092
onCompletionWithAuthResult ( authData ) ;
1087
1093
}
1094
+ firebase . fAuth = null ;
1088
1095
} ;
1089
- fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
1096
+ firebase . fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
1090
1097
1091
1098
} else {
1092
- fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1099
+ firebase . fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1093
1100
}
1094
1101
}
1095
1102
} ;
@@ -1138,9 +1145,8 @@ firebase.login = arg => {
1138
1145
appleIDRequest . nonce = sha256Nonce ;
1139
1146
1140
1147
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 ;
1144
1150
1145
1151
authorizationController . presentationContextProvider = ASAuthorizationControllerPresentationContextProvidingImpl . createWithOwnerAndCallback ( this as any ) ;
1146
1152
@@ -1164,38 +1170,37 @@ firebase.login = arg => {
1164
1170
sIn . scopes = arg . googleOptions . scopes ;
1165
1171
}
1166
1172
1167
- let delegate = GIDSignInDelegateImpl . new ( ) . initWithCallback ( ( user : GIDGoogleUser , error : NSError ) => {
1173
+ firebase . googleSignInDelegate = GIDSignInDelegateImpl . new ( ) . initWithCallback ( ( user : GIDGoogleUser , error : NSError ) => {
1168
1174
if ( error === null ) {
1169
1175
// Get a Google ID token and Google access token from the GIDAuthentication object and exchange them for a Firebase credential
1170
1176
firebase . _gIDAuthentication = user . authentication ;
1171
1177
const fIRAuthCredential = FIRGoogleAuthProvider . credentialWithIDTokenAccessToken ( firebase . _gIDAuthentication . idToken , firebase . _gIDAuthentication . accessToken ) ;
1172
1178
1173
1179
// Finally, authenticate with Firebase using the credential
1174
- if ( fAuth . currentUser ) {
1180
+ if ( firebase . fAuth . currentUser ) {
1175
1181
// link credential, note that you only want to do this if this user doesn't already use Google as an auth provider
1176
1182
const onCompletionLink = ( user , error ) => {
1177
1183
if ( error ) {
1178
1184
// ignore, as this one was probably already linked, so just return the user
1179
- fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1185
+ firebase . fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1180
1186
} else {
1181
1187
onCompletionWithAuthResult ( user ) ;
1182
1188
}
1189
+ firebase . fAuth = null ;
1183
1190
} ;
1184
- fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
1191
+ firebase . fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential , onCompletionLink ) ;
1185
1192
1186
1193
} else {
1187
- fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1194
+ firebase . fAuth . signInWithCredentialCompletion ( fIRAuthCredential , onCompletionWithAuthResult ) ;
1188
1195
}
1189
1196
1190
1197
} else {
1191
1198
reject ( error . localizedDescription ) ;
1192
1199
}
1193
- CFRelease ( delegate ) ;
1194
- delegate = undefined ;
1200
+ firebase . googleSignInDelegate = null ;
1195
1201
} ) ;
1196
1202
1197
- CFRetain ( delegate ) ;
1198
- sIn . delegate = delegate ;
1203
+ sIn . delegate = firebase . googleSignInDelegate ;
1199
1204
sIn . signIn ( ) ;
1200
1205
} else {
1201
1206
reject ( "Unsupported auth type: " + arg . type ) ;
@@ -2624,7 +2629,7 @@ class ASAuthorizationControllerDelegateImpl extends NSObject /* implements ASAut
2624
2629
if ( ASAuthorizationControllerDelegateImpl . ObjCProtocols . length === 0 && parseInt ( Device . osVersion ) >= 13 ) {
2625
2630
ASAuthorizationControllerDelegateImpl . ObjCProtocols . push ( ASAuthorizationControllerDelegate ) ;
2626
2631
}
2627
- let delegate = < ASAuthorizationControllerDelegateImpl > ASAuthorizationControllerDelegateImpl . new ( ) ;
2632
+ const delegate = < ASAuthorizationControllerDelegateImpl > ASAuthorizationControllerDelegateImpl . new ( ) ;
2628
2633
delegate . owner = owner ;
2629
2634
delegate . resolve = resolve ;
2630
2635
delegate . reject = reject ;
@@ -2667,7 +2672,7 @@ class ASAuthorizationControllerDelegateImpl extends NSObject /* implements ASAut
2667
2672
user : toLoginResult ( authResult . user )
2668
2673
} ) ;
2669
2674
this . resolve ( toLoginResult ( authResult && authResult . user , authResult && authResult . additionalUserInfo ) ) ;
2670
- CFRelease ( this ) ;
2675
+ firebase . appleAuthDelegate = null ;
2671
2676
}
2672
2677
} ) ;
2673
2678
}
@@ -2688,7 +2693,7 @@ class ASAuthorizationControllerPresentationContextProvidingImpl extends NSObject
2688
2693
if ( ASAuthorizationControllerPresentationContextProvidingImpl . ObjCProtocols . length === 0 && parseInt ( Device . osVersion ) >= 13 ) {
2689
2694
ASAuthorizationControllerPresentationContextProvidingImpl . ObjCProtocols . push ( ASAuthorizationControllerPresentationContextProviding ) ;
2690
2695
}
2691
- let delegate = < ASAuthorizationControllerPresentationContextProvidingImpl > ASAuthorizationControllerPresentationContextProvidingImpl . new ( ) ;
2696
+ const delegate = < ASAuthorizationControllerPresentationContextProvidingImpl > ASAuthorizationControllerPresentationContextProvidingImpl . new ( ) ;
2692
2697
delegate . owner = owner ;
2693
2698
return delegate ;
2694
2699
}
0 commit comments