From 48966c796417eb95cadb352d8f2dda5902fe4af9 Mon Sep 17 00:00:00 2001 From: Raphael Jenni Date: Thu, 16 Mar 2017 11:24:29 +0100 Subject: [PATCH 1/3] Added account linking for email on Android --- firebase.android.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/firebase.android.js b/firebase.android.js index 60e627bf..e8ae9b8e 100755 --- a/firebase.android.js +++ b/firebase.android.js @@ -819,7 +819,17 @@ firebase.login = function (arg) { if (!arg.email || !arg.password) { reject("Auth type emailandpassword requires an email and password argument"); } else { - firebaseAuth.signInWithEmailAndPassword(arg.email, arg.password).addOnCompleteListener(onCompleteListener); + var user = com.google.firebase.auth.FirebaseAuth.getInstance().getCurrentUser(); + if (user) { + if (firebase._alreadyLinkedToAuthProvider(user, "password")) { + firebaseAuth.signInWithEmailAndPassword(arg.email, arg.password).addOnCompleteListener(onCompleteListener); + } else { + var authCredential = com.google.firebase.auth.EmailAuthProvider.getCredential(arg.email, arg.password); + user.linkWithCredential(authCredential).addOnCompleteListener(onCompleteListener); + } + } else { + firebaseAuth.signInWithEmailAndPassword(arg.email, arg.password).addOnCompleteListener(onCompleteListener); + } } } else if (arg.type === firebase.LoginType.CUSTOM) { From dee62faa09fa47d49da1e1b225e76294d7d9e901 Mon Sep 17 00:00:00 2001 From: Raphael Jenni Date: Thu, 16 Mar 2017 15:27:23 +0100 Subject: [PATCH 2/3] Added account linking for email on iOS --- firebase.ios.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/firebase.ios.js b/firebase.ios.js index b9908380..6768de1b 100755 --- a/firebase.ios.js +++ b/firebase.ios.js @@ -931,7 +931,23 @@ firebase.login = function (arg) { if (!arg.email || !arg.password) { reject("Auth type emailandpassword requires an email and password argument"); } else { - fAuth.signInWithEmailPasswordCompletion(arg.email, arg.password, onCompletion); + var fIRAuthCredential = FIREmailPasswordAuthProvider.credential(arg.email, arg.password) + if (fAuth.currentUser) { + // link credential, note that you only want to do this if this user doesn't already use fb as an auth provider + var onCompletionLink = function (user, error) { + if (error) { + // ignore, as this one was probably already linked, so just return the user + log("--- linking error: " + error.localizedDescription); + fAuth.signInWithCredentialCompletion(fIRAuthCredential, onCompletion); + } else { + onCompletion(user); + } + }; + fAuth.currentUser.linkWithCredentialCompletion(fIRAuthCredential, onCompletionLink); + + } else { + fAuth.signInWithEmailPasswordCompletion(arg.email, arg.password, onCompletion); + } } } else if (arg.type === firebase.LoginType.CUSTOM) { From 4e19197c88da9c55a22bf91d74da740de081d81c Mon Sep 17 00:00:00 2001 From: Raphael Jenni Date: Thu, 16 Mar 2017 16:21:35 +0100 Subject: [PATCH 3/3] Fixed wrong method name in iOS --- firebase.ios.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase.ios.js b/firebase.ios.js index 6768de1b..764f007a 100755 --- a/firebase.ios.js +++ b/firebase.ios.js @@ -931,7 +931,7 @@ firebase.login = function (arg) { if (!arg.email || !arg.password) { reject("Auth type emailandpassword requires an email and password argument"); } else { - var fIRAuthCredential = FIREmailPasswordAuthProvider.credential(arg.email, arg.password) + var fIRAuthCredential = FIREmailPasswordAuthProvider.credentialWithEmailPassword(arg.email, arg.password) if (fAuth.currentUser) { // link credential, note that you only want to do this if this user doesn't already use fb as an auth provider var onCompletionLink = function (user, error) {