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

Commit

Permalink
#104 Is there some way to re-auth with Google Login
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Aug 15, 2016
1 parent d632074 commit 8bda3f9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
14 changes: 11 additions & 3 deletions firebase.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,12 @@ firebase.logout = function (arg) {
return new Promise(function (resolve, reject) {
try {
com.google.firebase.auth.FirebaseAuth.getInstance().signOut();

// also disconnect from Google otherwise ppl can't connect with a different account
if (firebase._mGoogleApiClient) {
com.google.android.gms.auth.api.Auth.GoogleSignInApi.revokeAccess(firebase._mGoogleApiClient);
}

resolve();
} catch (ex) {
console.log("Error in firebase.logout: " + ex);
Expand All @@ -423,7 +429,7 @@ function toLoginResult(user) {
name: user.getDisplayName(),
email: user.getEmail(),
// expiresAtUnixEpochSeconds: authData.getExpires(),
profileImageURL: user.getPhotoUrl() ? user.getPhotoUrl().toString() : null
profileImageURL: user.getPhotoUrl() ? user.getPhotoUrl().toString() : null
// token: user.getToken() // can be used to auth with a backend server
};
}
Expand Down Expand Up @@ -545,12 +551,12 @@ firebase.login = function (arg) {
}
});

var mGoogleApiClient = new com.google.android.gms.common.api.GoogleApiClient.Builder(appModule.android.context)
firebase._mGoogleApiClient = new com.google.android.gms.common.api.GoogleApiClient.Builder(appModule.android.context)
.addOnConnectionFailedListener(onConnectionFailedListener)
.addApi(com.google.android.gms.auth.api.Auth.GOOGLE_SIGN_IN_API, googleSignInOptions)
.build();

var signInIntent = com.google.android.gms.auth.api.Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
var signInIntent = com.google.android.gms.auth.api.Auth.GoogleSignInApi.getSignInIntent(firebase._mGoogleApiClient);

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

firebase._mGoogleApiClient.connect();

var user = com.google.firebase.auth.FirebaseAuth.getInstance().getCurrentUser();
if (user) {
if (firebase._alreadyLinkedToAuthProvider(user, "google.com")) {
Expand Down
22 changes: 13 additions & 9 deletions firebase.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,20 @@ firebase.addAppDelegateMethods = function(appDelegate) {
options.valueForKey(UIApplicationOpenURLOptionsSourceApplicationKey),
options.valueForKey(UIApplicationOpenURLOptionsAnnotationKey));
};

// Untested, so commented out
/*
appDelegate.prototype.signDidDisconnectWithUserWithError = function (signIn, user, error) {
/* no need for this one
appDelegate.prototype.signDidDisconnectWithUserWithError = function (signIn, user, error) {
if (error === null) {
console.log("--- OK in signDidDisconnectWithUserWithError");
} else {
console.log("--- error in signDidDisconnectWithUserWithError: " + error.localizedDescription);
console.log("--- error in signDidDisconnectWithUserWithError: " + error.localizedDescription);
}
};
*/
};
*/
}

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

Expand Down Expand Up @@ -464,6 +462,12 @@ firebase.logout = function (arg) {
return new Promise(function (resolve, reject) {
try {
FIRAuth.auth().signOut(null);

// also disconnect from Google otherwise ppl can't connect with a different account
if (typeof(GIDSignIn) !== "undefined") {
GIDSignIn.sharedInstance().disconnect();
}

resolve();
} catch (ex) {
console.log("Error in firebase.logout: " + ex);
Expand Down Expand Up @@ -1144,7 +1148,7 @@ firebase.deleteFile = function (arg) {
});
};

/* disabled since FIRCrashLog is always undefined
/*
firebase.sendCrashLog = function (arg) {
return new Promise(function (resolve, reject) {
try {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-plugin-firebase",
"version": "3.5.1",
"version": "3.5.2-dev",
"description" : "Fire. Base. Firebase!",
"main" : "firebase.js",
"nativescript": {
Expand Down

0 comments on commit 8bda3f9

Please sign in to comment.