<commit_before><template>
  <div>
    <div v-if="!keycloak || (keycloak && !keycloak.authenticated)">
      <button type="button" class="btn btn-light btn-sm" @click="keyCloakLogin()">Log in</button>
    </div>
    <div v-if="keycloak && keycloak.authenticated">
      <span class="userLoggedInText">{{ keycloak.tokenParsed.name }}</span>
      <button type="button" class="btn btn-light btn-sm" @click="keyCloakLogout()">Log out</button>
      </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Keycloak from 'keycloak-js'
import ApiService from '@/common/services/ApiService.js'
import { SET_KEYCLOAK } from '@/registry/store/mutations.types.js'

export default {
  data () {
    return {
      kc: null
    }
  },
  computed: {
    ...mapGetters(['user', 'keycloak'])
  },
  methods: {
    keyCloakInit () {
      const kc = Keycloak({
        'realm': 'gwells',
        'url': 'https://dev-sso.pathfinder.gov.bc.ca/auth',
        'clientId': 'webapp-dev-local'
      })
      kc.init({onLoad: 'check-sso'}).success(() => {
        this.kc = kc
        this.$store.commit(SET_KEYCLOAK, kc)
        ApiService.authHeader('JWT', kc.token)
      })
    },
    keyCloakLogin () {
      if (this.kc) {
        this.kc.login().success((authenticated) => {
          if (authenticated) {
            this.$store.commit(SET_KEYCLOAK, this.kc)
            ApiService.authHeader('JWT', this.kc.token)
          }
        })
      }
    },
    keyCloakLogout () {<commit_msg>add IDP hint<commit_after><template>
  <div>
    <div v-if="!keycloak || (keycloak && !keycloak.authenticated)">
      <button type="button" class="btn btn-light btn-sm" @click="keyCloakLogin()">Log in</button>
    </div>
    <div v-if="keycloak && keycloak.authenticated">
      <span class="userLoggedInText">{{ keycloak.tokenParsed.name }}</span>
      <button type="button" class="btn btn-light btn-sm" @click="keyCloakLogout()">Log out</button>
      </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Keycloak from 'keycloak-js'
import ApiService from '@/common/services/ApiService.js'
import { SET_KEYCLOAK } from '@/registry/store/mutations.types.js'

export default {
  data () {
    return {
      kc: null
    }
  },
  computed: {
    ...mapGetters(['user', 'keycloak'])
  },
  methods: {
    keyCloakInit () {
      const kc = Keycloak({
        'realm': 'gwells',
        'url': 'https://dev-sso.pathfinder.gov.bc.ca/auth',
        'clientId': 'webapp-dev-local'
      })

      kc.init({onLoad: 'check-sso'}).success(() => {
        this.kc = kc
        this.$store.commit(SET_KEYCLOAK, kc)
        ApiService.authHeader('JWT', kc.token)
      })
    },
    keyCloakLogin () {
      if (this.kc) {
        this.kc.login({ idpHint: 'idir' }).success((authenticated) => {
          if (authenticated) {
            this.$store.commit(SET_KEYCLOAK, this.kc)
            ApiService.authHeader('JWT', this.kc.token)
          }
        })
      }
    },
    keyCloakLogout () {
{'fraction_non_alphanumeric': 0.17713526088401463, 'fraction_numerical': 0.0, 'mean_word_length': 2.5961768219832737, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 37, 'https://': 2, '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': '7645517', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1074, 'n_words': 179}