title: Firebase JS API auth - account-exists-with-different-credential
body: <p>We're having real problems trying to resolve this and so hoping for some Firebase assistance / those that have solved the same problem.</p>
  
  <p>The app is React Native (0.43.2) and using Firebase JS API (latest)</p>
  
  <p>We provide Facebook and Google auth. Works fine.</p>
  
  <p>BUT, if a user:</p>
  
  <ol>
  <li>signs in with Facebook (is ok)</li>
  <li>later, signs in with Google  (is also fine)</li>
  <li>later, tries to sign in with Facebook - BOOM! not so fine and Firebase returns this error:</li>
  </ol>
  
  <p><code>auth/account-exists-with-different-credential</code></p>
  
  <p>From reading docs and a few posts on SO, we thought the following was correct but clearly not as we're getting the same auth error back.</p>
  
  <pre><code>...error returned by Firebase auth after trying Facebook login...
  
  const email = error.email;
  const pendingCred = error.credential;
  
  firebase.auth().fetchProvidersForEmail(email)
  .then(providers =&gt; {
     //providers returns this array -&gt; ["google.com"]
     firebase.auth().signInWithCredential(pendingCred)
     .then(result =&gt; {
         result.user.link(pendingCred)
     })
     .catch(error =&gt; log(error))
  </code></pre>
  
  <p>The call to signInWithCredential is throwing the same error <code>auth/account-exists-with-different-credential</code>. </p>
  
  <p>Can anyone help point out what we are doing wrong with this implementation? Greatly appreciated.</p>