async forceTokenUpdate()

in src/auth/auth-core.ts [528:577]


  async forceTokenUpdate(): Promise<string | null> {
    try {
      if (!this._backendCheckPromise) {
        this._backendCheckPromise = this._checkBackendsStatusesIfEnabled();
      }
      await this._backendCheckPromise;
    } catch (e) {
      throw new Error('Cannot refresh token: backend is not available. Postponed by user.');
    } finally {
      this._backendCheckPromise = null;
    }

    try {
      return (await this._backgroundFlow?.authorize()) ?? null;
    } catch (error) {
      if (!(error instanceof Error)) {
        return null;
      }
      if (this._canShowDialogs()) {
        return new Promise(resolve => {
          const onTryAgain = async () => {
            try {
              const result = await this._backgroundFlow?.authorize();
              resolve(result ?? null);
            } catch (retryError) {
              if (retryError instanceof Error) {
                this._showAuthDialog({
                  nonInteractive: true,
                  error: retryError,
                  onTryAgain,
                });
              }
              throw retryError;
            }
          };
          this._showAuthDialog({
            nonInteractive: true,
            error: error as Error,
            onTryAgain,
          });
        });
      }
      const authRequest = await this._requestBuilder?.prepareAuthRequest();
      if (authRequest) {
        this._redirectCurrentPage(authRequest.url);
      }

      throw new TokenValidator.TokenValidationError(error.message);
    }
  }