<commit_before>import { Injectable } from '@angular/core';
import { SiteService } from './site.service';
import { Client } from '../../services/api/client';
import { Session } from '../../services/session';
import { ConfigsService } from './configs.service';

@Injectable()
export class SsoService {
  protected readonly siteUrl: string;

  constructor(
    protected site: SiteService,
    protected client: Client,
    protected session: Session,
    configs: ConfigsService
  ) {
    this.siteUrl = configs.get('site_url');
    this.listen();
  }

  listen() {
    this.session.isLoggedIn((is: boolean) => {
      if (is) {
        this.auth();
      }
    });
  }

  isRequired(): boolean {
    return this.site.isProDomain;
  }

  async connect() {
    try {
      const connect: any = await this.client.postRaw(
        `${this.siteUrl}api/v2/sso/connect`
      );

      if (connect && connect.token && connect.status === 'success') {
        const authorization: any = await this.client.post(
          'api/v2/sso/authorize',
          {
            token: connect.token,
          }
        );

        if (authorization && authorization.user) {
          this.session.inject(authorization.user);
        }
      }
    } catch (e) {
      console.error(e);
    }
  }

  async auth() {
    try {
      const connect: any = await this.client.post('api/v2/sso/connect');

      if (connect && connect.token && connect.status === 'success') {
        await this.client.postRaw(`${this.siteUrl}api/v2/sso/authorize`, {
          token: connect.token,
        });
      }
    } catch (e) {
      console.error(e);
    }
  }
}<commit_msg>(fix): pro sites should wait for configs to be resolved<commit_after>import { Injectable } from '@angular/core';
import { SiteService } from './site.service';
import { Client } from '../../services/api/client';
import { Session } from '../../services/session';
import { ConfigsService } from './configs.service';

@Injectable()
export class SsoService {
  constructor(
    protected site: SiteService,
    protected client: Client,
    protected session: Session,
    private configs: ConfigsService
  ) {
    this.listen();
  }

  listen() {
    this.session.isLoggedIn((is: boolean) => {
      if (is) {
        this.auth();
      }
    });
  }

  isRequired(): boolean {
    return this.site.isProDomain;
  }

  async connect() {
    try {
      const connect: any = await this.client.postRaw(
        `${this.configs.get('site_url')}api/v2/sso/connect`
      );

      if (connect && connect.token && connect.status === 'success') {
        const authorization: any = await this.client.post(
          'api/v2/sso/authorize',
          {
            token: connect.token,
          }
        );

        if (authorization && authorization.user) {
          this.session.inject(authorization.user);
        }
      }
    } catch (e) {
      console.error(e);
    }
  }

  async auth() {
    try {
      const connect: any = await this.client.post('api/v2/sso/connect');

      if (connect && connect.token && connect.status === 'success') {
        await this.client.postRaw(
          `${this.configs.get('site_url')}api/v2/sso/authorize`,
          {
            token: connect.token,
          }
        );
      }
    } catch (e) {
      console.error(e);
    }
  }
}
{'fraction_non_alphanumeric': 0.15173453996983408, 'fraction_numerical': 0.0024132730015082957, 'mean_word_length': 2.1611058150619638, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7644910', 'n_tokens_mistral': 1028, 'n_tokens_neox': 1018, 'n_words': 209}