title: Firebase Auth and Google Sign-in
body: <p>I am using javascript to log into firebase auth and my hopes are to access google drive using the same process to avoid signing into google twice. </p>
  
  <p>Looking at the docs at <a href="https://firebase.google.com/docs/auth/web/google-signin" rel="nofollow noreferrer">https://firebase.google.com/docs/auth/web/google-signin</a> I can see that it says "This gives you a Google Access Token. You can use it to access the Google API."</p>
  
  <pre><code>firebase.auth().signInWithPopup(provider).then(function(result) {
    // This gives you a Google Access Token. You can use it to access the Google API.
    var token = result.credential.accessToken;
    // The signed-in user info.
    var user = result.user;
    // ...
  }).catch(function(error) {
    // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
    // The email of the user's account used.
    var email = error.email;
    // The firebase.auth.AuthCredential type that was used.
    var credential = error.credential;
    // ...
  });
  </code></pre>
  
  <p>Currently, I am able to log into them both separately by calling this afterward:</p>
  
  <pre><code>gapi.auth2.getAuthInstance().signIn();
  </code></pre>
  
  <p>but this produces two sign-ins for the user. The goal, for now, is to have the user sign into firebase auth and then list the user's files from google afterward without a double sign in. </p>
  
  <pre><code>function appendPre(message) {
      var pre = document.getElementById('form-results-ul');
      var textContent = document.createTextNode(message + '\n');
      pre.appendChild(textContent);
  }
  
  function listFiles() {
      gapi.client.drive.files.list({
          'pageSize': 10,
          'fields': "nextPageToken, files(id, name)"
      }).then(function (response) {
          appendPre('Files:');
          var files = response.result.files;
          if (files &amp;&amp; files.length &gt; 0) {
              for (var i = 0; i &lt; files.length; i++) {
                  var file = files[i];
                  appendPre(file.name + ' (' + file.id + ')');
              }
          } else {
              appendPre('No files found.');
          }
      });
  }
  </code></pre>