title: Google sign-in button in Angular 2+
body: <p>I'm trying to add a login/logout to/from google by their guide:
  <a href="https://developers.google.com/identity/sign-in/web/sign-in" rel="noreferrer">https://developers.google.com/identity/sign-in/web/sign-in</a></p>
  
  <p>But I'm facing some problems.</p>
  
  <p><strong>index.html:</strong></p>
  
  <pre><code>  &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
    &lt;script src="https://apis.google.com/js/platform.js" async defer&gt;&lt;/script&gt;
    &lt;meta name="google-signin-client_id" content="**my-google-api-key**.apps.googleusercontent.com"&gt;
    &lt;script&gt;
      gapi.load('auth2',function () {
        gapi.auth2.init();
      });
    &lt;/script&gt;
  </code></pre>
  
  <p><strong>app.component.html:</strong></p>
  
  <pre><code>&lt;div class="g-signin2" data-onsuccess="onSignIn"&gt;&lt;/div&gt;
  &lt;a href="#" onclick="signOut();"&gt;Sign out&lt;/a&gt;
  </code></pre>
  
  <p><strong>app.component.ts:</strong></p>
  
  <pre><code>public onSignIn(googleUser):void {
      var profile = googleUser.getBasicProfile();
      console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
      console.log('Name: ' + profile.getName());
      console.log('Image URL: ' + profile.getImageUrl());
      console.log('Email: ' + profile.getEmail());
    }
    public signOut():void {
      var auth2 = gapi.auth2.getAuthInstance();
      auth2.signOut().then(function () {
        console.log('User signed out.');
      });
    }
  </code></pre>
  
  <p><strong>Problems:</strong></p>
  
  <ol>
  <li>After logging in succussfully, onSignIn function does not get called so nothing is printed but the signIn is working.</li>
  <li>In the signOut function I have error: "Cannot find name 'gapi'." but the signout is working.</li>
  </ol>
  
  <p><strong>Question:</strong></p>
  
  <p>Google tells us not to use the googleUser.getBasicProfile().getId() as the user ID but use the ID Token intead: googleUser.getAuthResponse().id_token.sub. 
  <strong>Why?</strong></p>