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

Commit 8bda3f9

Browse files
#104 Is there some way to re-auth with Google Login
1 parent d632074 commit 8bda3f9

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

firebase.android.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,12 @@ firebase.logout = function (arg) {
405405
return new Promise(function (resolve, reject) {
406406
try {
407407
com.google.firebase.auth.FirebaseAuth.getInstance().signOut();
408+
409+
// also disconnect from Google otherwise ppl can't connect with a different account
410+
if (firebase._mGoogleApiClient) {
411+
com.google.android.gms.auth.api.Auth.GoogleSignInApi.revokeAccess(firebase._mGoogleApiClient);
412+
}
413+
408414
resolve();
409415
} catch (ex) {
410416
console.log("Error in firebase.logout: " + ex);
@@ -423,7 +429,7 @@ function toLoginResult(user) {
423429
name: user.getDisplayName(),
424430
email: user.getEmail(),
425431
// expiresAtUnixEpochSeconds: authData.getExpires(),
426-
profileImageURL: user.getPhotoUrl() ? user.getPhotoUrl().toString() : null
432+
profileImageURL: user.getPhotoUrl() ? user.getPhotoUrl().toString() : null
427433
// token: user.getToken() // can be used to auth with a backend server
428434
};
429435
}
@@ -545,12 +551,12 @@ firebase.login = function (arg) {
545551
}
546552
});
547553

548-
var mGoogleApiClient = new com.google.android.gms.common.api.GoogleApiClient.Builder(appModule.android.context)
554+
firebase._mGoogleApiClient = new com.google.android.gms.common.api.GoogleApiClient.Builder(appModule.android.context)
549555
.addOnConnectionFailedListener(onConnectionFailedListener)
550556
.addApi(com.google.android.gms.auth.api.Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
551557
.build();
552558

553-
var signInIntent = com.google.android.gms.auth.api.Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
559+
var signInIntent = com.google.android.gms.auth.api.Auth.GoogleSignInApi.getSignInIntent(firebase._mGoogleApiClient);
554560

555561
firebase._rememberedContext = appModule.android.currentContext;
556562
appModule.android.currentContext.startActivityForResult(signInIntent, GOOGLE_SIGNIN_INTENT_ID);
@@ -569,6 +575,8 @@ firebase.login = function (arg) {
569575
var accessToken = null;
570576
var authCredential = com.google.firebase.auth.GoogleAuthProvider.getCredential(idToken, accessToken);
571577

578+
firebase._mGoogleApiClient.connect();
579+
572580
var user = com.google.firebase.auth.FirebaseAuth.getInstance().getCurrentUser();
573581
if (user) {
574582
if (firebase._alreadyLinkedToAuthProvider(user, "google.com")) {

firebase.ios.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,20 @@ firebase.addAppDelegateMethods = function(appDelegate) {
4444
options.valueForKey(UIApplicationOpenURLOptionsSourceApplicationKey),
4545
options.valueForKey(UIApplicationOpenURLOptionsAnnotationKey));
4646
};
47-
48-
// Untested, so commented out
49-
/*
50-
appDelegate.prototype.signDidDisconnectWithUserWithError = function (signIn, user, error) {
47+
/* no need for this one
48+
appDelegate.prototype.signDidDisconnectWithUserWithError = function (signIn, user, error) {
5149
if (error === null) {
5250
console.log("--- OK in signDidDisconnectWithUserWithError");
5351
} else {
54-
console.log("--- error in signDidDisconnectWithUserWithError: " + error.localizedDescription);
52+
console.log("--- error in signDidDisconnectWithUserWithError: " + error.localizedDescription);
5553
}
56-
};
57-
*/
54+
};
55+
*/
5856
}
5957

6058
// making this conditional to avoid http://stackoverflow.com/questions/37428539/firebase-causes-issue-missing-push-notification-entitlement-after-delivery-to ?
6159
if (typeof(FIRMessaging) !== "undefined") {
62-
appDelegate.prototype.applicationDidReceiveRemoteNotificationFetchCompletionHandler = function (application, userInfo, completionHandler) {
60+
appDelegate.prototype.applicationDidReceiveRemoteNotificationFetchCompletionHandler = function (application, userInfo, completionHandler) {
6361
completionHandler(UIBackgroundFetchResultNewData);
6462
var userInfoJSON = firebase.toJsObject(userInfo);
6563

@@ -464,6 +462,12 @@ firebase.logout = function (arg) {
464462
return new Promise(function (resolve, reject) {
465463
try {
466464
FIRAuth.auth().signOut(null);
465+
466+
// also disconnect from Google otherwise ppl can't connect with a different account
467+
if (typeof(GIDSignIn) !== "undefined") {
468+
GIDSignIn.sharedInstance().disconnect();
469+
}
470+
467471
resolve();
468472
} catch (ex) {
469473
console.log("Error in firebase.logout: " + ex);
@@ -1144,7 +1148,7 @@ firebase.deleteFile = function (arg) {
11441148
});
11451149
};
11461150

1147-
/* disabled since FIRCrashLog is always undefined
1151+
/*
11481152
firebase.sendCrashLog = function (arg) {
11491153
return new Promise(function (resolve, reject) {
11501154
try {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-plugin-firebase",
3-
"version": "3.5.1",
3+
"version": "3.5.2-dev",
44
"description" : "Fire. Base. Firebase!",
55
"main" : "firebase.js",
66
"nativescript": {

0 commit comments

Comments
 (0)