This repository was archived by the owner on Apr 4, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments