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

Implemented email account linking #316

Merged
merged 3 commits into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion firebase.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 17 additions & 1 deletion firebase.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.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) {
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) {
Expand Down