This repository was archived by the owner on Apr 4, 2023. It is now read-only.
  
  
  
  
    
    
    
      
    
  
  
    
File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -830,7 +830,17 @@ firebase.login = function (arg) {
830830        if  ( ! arg . email  ||  ! arg . password )  { 
831831          reject ( "Auth type emailandpassword requires an email and password argument" ) ; 
832832        }  else  { 
833-           firebaseAuth . signInWithEmailAndPassword ( arg . email ,  arg . password ) . addOnCompleteListener ( onCompleteListener ) ; 
833+             var  user  =  com . google . firebase . auth . FirebaseAuth . getInstance ( ) . getCurrentUser ( ) ; 
834+             if  ( user )  { 
835+                 if  ( firebase . _alreadyLinkedToAuthProvider ( user ,  "password" ) )  { 
836+                     firebaseAuth . signInWithEmailAndPassword ( arg . email ,  arg . password ) . addOnCompleteListener ( onCompleteListener ) ; 
837+                 }  else  { 
838+                     var  authCredential  =  com . google . firebase . auth . EmailAuthProvider . getCredential ( arg . email ,  arg . password ) ; 
839+                     user . linkWithCredential ( authCredential ) . addOnCompleteListener ( onCompleteListener ) ; 
840+                 } 
841+             }  else  { 
842+                 firebaseAuth . signInWithEmailAndPassword ( arg . email ,  arg . password ) . addOnCompleteListener ( onCompleteListener ) ; 
843+             } 
834844        } 
835845
836846      }  else  if  ( arg . type  ===  firebase . LoginType . CUSTOM )  { 
Original file line number Diff line number Diff line change @@ -937,7 +937,23 @@ firebase.login = function (arg) {
937937        if  ( ! arg . email  ||  ! arg . password )  { 
938938          reject ( "Auth type emailandpassword requires an email and password argument" ) ; 
939939        }  else  { 
940-           fAuth . signInWithEmailPasswordCompletion ( arg . email ,  arg . password ,  onCompletion ) ; 
940+             var  fIRAuthCredential  =  FIREmailPasswordAuthProvider . credentialWithEmailPassword ( arg . email ,  arg . password ) 
941+             if  ( fAuth . currentUser )  { 
942+                 // link credential, note that you only want to do this if this user doesn't already use fb as an auth provider 
943+                 var  onCompletionLink  =  function  ( user ,  error )  { 
944+                     if  ( error )  { 
945+                         // ignore, as this one was probably already linked, so just return the user 
946+                         log ( "--- linking error: "  +  error . localizedDescription ) ; 
947+                         fAuth . signInWithCredentialCompletion ( fIRAuthCredential ,  onCompletion ) ; 
948+                     }  else  { 
949+                         onCompletion ( user ) ; 
950+                     } 
951+                 } ; 
952+                 fAuth . currentUser . linkWithCredentialCompletion ( fIRAuthCredential ,  onCompletionLink ) ; 
953+ 
954+             }  else  { 
955+                 fAuth . signInWithEmailPasswordCompletion ( arg . email ,  arg . password ,  onCompletion ) ; 
956+             } 
941957        } 
942958
943959      }  else  if  ( arg . type  ===  firebase . LoginType . CUSTOM )  { 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments