Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 3ba799c

Browse files
Can't re-login with Facebook #1057
1 parent 3d9c040 commit 3ba799c

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

src/firebase.android.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -351,19 +351,6 @@ firebase.init = arg => {
351351
firebase.storageBucket = com.google.firebase.storage.FirebaseStorage.getInstance().getReferenceFromUrl(arg.storageBucket);
352352
}
353353

354-
// Facebook
355-
if (typeof (com.facebook) !== "undefined" && typeof (com.facebook.FacebookSdk) !== "undefined") {
356-
com.facebook.FacebookSdk.sdkInitialize(com.tns.NativeScriptApplication.getInstance());
357-
fbCallbackManager = com.facebook.CallbackManager.Factory.create();
358-
const callback = (eventData: AndroidActivityResultEventData) => {
359-
if (eventData.requestCode !== GOOGLE_SIGNIN_INTENT_ID) {
360-
appModule.android.off(appModule.AndroidApplication.activityResultEvent, callback);
361-
fbCallbackManager.onActivityResult(eventData.requestCode, eventData.resultCode, eventData.intent);
362-
}
363-
};
364-
appModule.android.on(appModule.AndroidApplication.activityResultEvent, callback);
365-
}
366-
367354
// Firebase AdMob
368355
if (typeof (com.google.android.gms.ads) !== "undefined" && typeof (com.google.android.gms.ads.MobileAds) !== "undefined") {
369356
// init admob
@@ -928,11 +915,23 @@ firebase.login = arg => {
928915
}
929916

930917
} else if (arg.type === firebase.LoginType.FACEBOOK) {
931-
if (typeof (com.facebook) === "undefined") {
918+
if (typeof (com.facebook) === "undefined" || typeof (com.facebook.FacebookSdk) === "undefined") {
932919
reject("Facebook SDK not installed - see gradle config");
933920
return;
934921
}
935922

923+
// Lazy loading the Facebook callback manager
924+
if (!fbCallbackManager) {
925+
com.facebook.FacebookSdk.sdkInitialize(com.tns.NativeScriptApplication.getInstance());
926+
fbCallbackManager = com.facebook.CallbackManager.Factory.create();
927+
}
928+
929+
const callback = (eventData: AndroidActivityResultEventData) => {
930+
appModule.android.off(appModule.AndroidApplication.activityResultEvent, callback);
931+
fbCallbackManager.onActivityResult(eventData.requestCode, eventData.resultCode, eventData.intent);
932+
};
933+
appModule.android.on(appModule.AndroidApplication.activityResultEvent, callback);
934+
936935
const fbLoginManager = com.facebook.login.LoginManager.getInstance();
937936
fbLoginManager.registerCallback(
938937
fbCallbackManager,
@@ -952,12 +951,8 @@ firebase.login = arg => {
952951
firebaseAuth.signInWithCredential(authCredential).addOnCompleteListener(onCompleteListener);
953952
}
954953
},
955-
onCancel: () => {
956-
reject("Facebook Login canceled");
957-
},
958-
onError: ex => {
959-
reject("Error while trying to login with Fb " + ex);
960-
}
954+
onCancel: () => reject("Facebook Login canceled"),
955+
onError: ex => reject("Error while trying to login with Fb " + ex)
961956
})
962957
);
963958

@@ -1029,7 +1024,7 @@ firebase.login = arg => {
10291024
firebaseAuth.signInWithCredential(authCredential).addOnCompleteListener(onCompleteListener);
10301025
}
10311026
} else {
1032-
console.log("Make sure you've uploaded your SHA1 fingerprint(s) to the Firebase console");
1027+
console.log("Make sure you've uploaded your SHA1 fingerprint(s) to the Firebase console. Status: " + googleSignInResult.getStatus());
10331028
reject("Has the SHA1 fingerprint been uploaded? Sign-in status: " + googleSignInResult.getStatus());
10341029
}
10351030
}

0 commit comments

Comments
 (0)