refresh token keycloak js

I work with keycloak-js version 8.0.1, i have a function getToken that tests either the token is expired in that case it refreshes it, or the token is not expired so it returns it. The problem is that when the token is expired it displays the warning msg but it does’t change it

@Injectable()
export class TokenService {

static auth: any = {};

constructor() { }

 static init(): Promise<any> {
    const keycloakAuth: Keycloak.KeycloakInstance = Keycloak({
        url: config.keycloak.url,
        realm: config.keycloak.realm,
        clientId: config.keycloak.clientId
    });
    return new Promise((resolve, reject) => {
        keycloakAuth.init({ onLoad: 'check-sso', flow: 'implicit', checkLoginIframe: false }).success(() => {
            TokenService.auth.authz = keycloakAuth;
            resolve();
        }).error(() => {
            reject();
        });
    });
 }

 getToken(): Promise<string> {
    return new Promise<string>((resolve, reject) => {
        if (TokenService.auth.authz.isTokenExpired()) {
             console.warn("Token expired !");
            TokenService.auth.authz.updateToken(1800).success(() => {
                console.log("Token updated");
                resolve(<string>TokenService.auth.authz.token);
            }).error(() => {
                reject('Failed to refresh token');
            });
        } else {
            resolve(<string>TokenService.auth.authz.token);
        }
    });
 }
}

Implicit flow doesn’t provide refresh token. Also implicit flow is not recommend anymore, but authorization code flow with PKCE should be used instead.