Skip to content

Commit

Permalink
Merge pull request #49 from AplinkosMinisterija/api-fix
Browse files Browse the repository at this point in the history
api config
  • Loading branch information
DovMa authored Feb 7, 2024
2 parents bbd3806 + 04dbc31 commit 2e0009f
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,21 @@ interface Create {
id?: string;
}

const token = cookies.get('token');
const profileId = cookies.get('profileId');

class Api {
private AuthApiAxios: AxiosInstance;
private readonly proxy: string = '/api';

constructor() {
this.AuthApiAxios = Axios.create();

this.AuthApiAxios.interceptors.request.use(
(config) => {
if (!config.url) {
return config;
}

config.url = this.proxy + config.url;
const token = cookies.get('token');
const profileId = cookies.get('profileId');
if (token) {
config.headers!.Authorization = 'Bearer ' + token;

if (isFinite(parseInt(profileId))) config.headers!['X-Profile'] = profileId;
}

config.url = this.proxy + config.url;
return config;
},
(error) => {
Expand Down Expand Up @@ -417,6 +409,9 @@ class Api {
};

getExcel = async ({ filter }: TableList): Promise<any> => {
const token = cookies.get('token');
const profileId = cookies.get('profileId');

const response = await fetch(
`${this.proxy}/${Resources.EXCEL}?filter=${JSON.stringify(filter)}`,
{
Expand Down

0 comments on commit 2e0009f

Please sign in to comment.