title: Angular 6 with Google sign in: How to redirect on success
body: <p><strong>What's going on</strong></p>
  
  <p>I have a component which answers to unauthenticated users by showing them a Google Sign In button. When a user signs in the access token is sent to my server and it verifies it and returns a jsonwebtoken. I've followed Google's own documentation on how to implement the sign in and it's all working.</p>
  
  <p><strong>The problem</strong></p>
  
  <p>This is the first time I've used Google sign in, hence I'm a bit confused and not sure of how this is supposed to be set up. In my component I have the following click handler, which is called from the <code>ngAfterViewInit()</code>:</p>
  
  <pre><code>...
      auth2.attachClickHandler(button, {},
        (googleUser) =&gt; {
          let accessToken = this.googleUser.getAuthResponse().id_token;
  
          this.authService.authenticate(accessToken).then(res =&gt; {
            if (res.token) {
              this.authService.setToken(res.token);
  
              // I want to redirect to /dashboard
              this.router.navigateByUrl('/dashboard');
  
            }
          })
          .catch(err =&gt; {
            ...
          })
        }
     ));
  ...
  </code></pre>
  
  <p>But on success I want to redirect and Angular gives me the warning:</p>
  
  <pre><code>Navigation triggered outside Angular zone, did you forget to call 'ngZone.run()'?
  </code></pre>
  
  <p>How am I supposed to redirect if I'm in the <code>ngAfterViewInit</code> lifecycle? </p>
  
  <p><strong>Further questions</strong></p>
  
  <p>I want the user to be able to sign out on another page. But since <code>gapi.auth2</code> is undefined at this point, am I supposed to initialize auth2 once again? Meaning run <code>gapi.load('auth2', ...)</code> to get the authInstance and call disconnect and so forth? </p>
  
  <p>Also, is <code>gapi.auth2</code> the equivalent of Oauth2? </p>