setupGoogleLogin()

in pathology/viewer/src/services/auth.service.ts [90:124]


  setupGoogleLogin() {
    if (!isPlatformBrowser(this.platformId) || !window ||
        !environment.OAUTH_CLIENT_ID) {
      return;
    }

    window.onGoogleLibraryLoad = async () => {
      google.accounts.id.initialize({
        // Ref:
        // https://developers.google.com/identity/gsi/web/reference/js-reference#IdConfiguration
        client_id: environment.OAUTH_CLIENT_ID,
        callback: this.handleCredentialResponse.bind(this),
        auto_select: false,
        cancel_on_tap_outside: false
      });

      google.accounts!.id.renderButton(
          document!.getElementById('loginBtn')!,
          {theme: 'outline', size: 'large', width: 200, type: 'standard'});

      if (this.windowService.getLocalStorageItem(CREDENTIAL_STORAGE_KEY)) {
        let accessToken = this.getCachedAccessToken();
        if (accessToken && this.isTokenExpired(accessToken)) {
          await this.fetchAccessToken();
          accessToken = this.getCachedAccessToken();
        }
        if (accessToken && !this.isTokenExpired(accessToken)) {
          this.navigateToSearchIfAuth();
        }
        return;
      }

      google.accounts.id.prompt();
    };
  }