import { Store } from 'vuex';
import axios from 'axios';

const TENANT = 'uberctx-tenant';

export function addTenantInterceptor(store: Store<unknown>): void {
  const user = store.getters['oidcClient/currentUser'] || {};
  if (user[TENANT]) {
    axios.interceptors.request.use((config) => {
      config.headers.common[TENANT] = user[TENANT];
      return config;
    });
  }
}
