title: How to keep session active while using keycloak in Angular 7?
body: <p>I'm using this plugin <a href="https://github.com/mauriciovigolo/keycloak-angular" rel="nofollow noreferrer">https://github.com/mauriciovigolo/keycloak-angular</a> in Angular 7 project.</p>
  
  <p>Version:</p>
  
  <pre><code>keycloak-angular : 6.1.0
  angular : 7.1.4
  </code></pre>
  
  <p>After logged in successfully , this is the response I get from <code>/protocol/openid-connect/token</code>:<br></p>
  
  <pre><code>expires_in : 1980
  refresh_expires_in : 1800
  </code></pre>
  
  <p>It automatically logs out the user and redirecting to login page after 30 minutes. This behavior is annoying. I want this to behave as if nothing has happened as long as user is interacting with the application. In other words do not automatically log out after 30 minutes, it should keep the session active.</p>
  
  <p>Could someone guide me what exact steps are needed to achieve this? </p>
  
  <p><strong>Edit 1</strong></p>
  
  <p>As @thijsfranck suggested in his answer I modified the code like this, and it worked.</p>
  
  <p><code>app-init.ts</code></p>
  
  <pre><code>import {KeycloakService} from 'keycloak-angular';
  export function initializer(keycloak: KeycloakService) {
    return () =&gt; {
      return new Promise(async (resolve, reject) =&gt; {
        try {
          const _REALM = "realm";
          const _URL = "http://example.com";
          const _CLIENT_ID = "id"
  
          await keycloak.init({
            config: {
              realm: _REALM,
              url: _URL,
              clientId: _CLIENT_ID,
            },
            initOptions: {
              onLoad: 'login-required',
              checkLoginIframe: false
            },
            enableBearerInterceptor: true,
            bearerExcludedUrls: ['/assets', '/clients/public']
          })
  
          const keycloakAuth = keycloak.getKeycloakInstance();
  
          const updateToken = async (): Promise &lt; string &gt; =&gt; {
            const {success,error} = keycloakAuth.updateToken(5);
            return new Promise &lt; string &gt; ((res, rej) =&gt; {
              success(() =&gt; res(keycloakAuth.token));
              error(rej);
            });
          }
          const login = async (): Promise &lt; void &gt; =&gt; {
            const {success,error} = keycloakAuth.login();
            return new Promise &lt; void &gt; ((res2, rej2) =&gt; {
              success(res2);
              error(rej2);
            });
          }
  
  
          keycloakAuth.onTokenExpired = () =&gt; {
            if (keycloakAuth.refreshToken) {
              updateToken();
            } else {
              login();
            }
          }
  
          resolve();
        } catch (error) {
          reject(error);
        }
      });
    };
  }
  </code></pre>
  
  <p>Here is <code>app.module.ts</code></p>
  
  <pre><code>providers: [
      {
        provide: APP_INITIALIZER,
        useFactory: initializer,
        multi: true,
        deps: [KeycloakService]
      }
    ]
  </code></pre>