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

Commit b41d854

Browse files
author
Raphael Jenni
committed
Added account linking for email on iOS
1 parent 1a20a04 commit b41d854

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

firebase.ios.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,23 @@ firebase.login = function (arg) {
931931
if (!arg.email || !arg.password) {
932932
reject("Auth type emailandpassword requires an email and password argument");
933933
} else {
934-
fAuth.signInWithEmailPasswordCompletion(arg.email, arg.password, onCompletion);
934+
var fIRAuthCredential = FIREmailPasswordAuthProvider.credential(arg.email, arg.password)
935+
if (fAuth.currentUser) {
936+
// link credential, note that you only want to do this if this user doesn't already use fb as an auth provider
937+
var onCompletionLink = function (user, error) {
938+
if (error) {
939+
// ignore, as this one was probably already linked, so just return the user
940+
log("--- linking error: " + error.localizedDescription);
941+
fAuth.signInWithCredentialCompletion(fIRAuthCredential, onCompletion);
942+
} else {
943+
onCompletion(user);
944+
}
945+
};
946+
fAuth.currentUser.linkWithCredentialCompletion(fIRAuthCredential, onCompletionLink);
947+
948+
} else {
949+
fAuth.signInWithEmailPasswordCompletion(arg.email, arg.password, onCompletion);
950+
}
935951
}
936952

937953
} else if (arg.type === firebase.LoginType.CUSTOM) {

0 commit comments

Comments
 (0)