Skip to content

Commit

Permalink
Merge pull request #227 from bcgov/fix-jwt-issue
Browse files Browse the repository at this point in the history
always require jwt auth
  • Loading branch information
mgtennant committed Aug 29, 2024
2 parents 39532e0 + f9bd4fa commit 03af3b6
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions frontend/src/app/common/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@ export const get = <T, M = {}>(parameters: ApiRequestParameters<M>, headers?: {}
const { url, requiresAuthentication, params } = parameters;
let config: AxiosRequestConfig = { headers: headers };

if (requiresAuthentication) {
config.headers = {
...config.headers,
Authorization: `Bearer ${UserService.getToken()}`,
};
}
// always send JWT
config.headers = {
...config.headers,
Authorization: `Bearer ${UserService.getToken()}`,
};

if (params) {
config.params = params;
Expand All @@ -90,7 +89,7 @@ export const post = <T, M = {}>(parameters: ApiRequestParameters<M>): Promise<T>
const { url, requiresAuthentication, params } = parameters;
let config: AxiosRequestConfig = { headers: {} };

if (requiresAuthentication && config && config.headers) {
if (config && config.headers) {
config.headers['Authorization'] = `Bearer ${UserService.getToken()}`;
}

Expand All @@ -101,7 +100,7 @@ const fileDownloadGet = <T, M = {}>(parameters: ApiRequestParameters<M>): Promis
const { url, requiresAuthentication } = parameters;
let config: AxiosRequestConfig = { headers: {}, responseType: 'blob' };

if (requiresAuthentication && config && config.headers) {
if (config && config.headers) {
config.headers['Authorization'] = `Bearer ${UserService.getToken()}`;
}

Expand All @@ -112,7 +111,7 @@ const fileDownloadPost = <T, M = {}>(parameters: ApiRequestParameters<M>): Promi
const { url, requiresAuthentication, params } = parameters;
let config: AxiosRequestConfig = { headers: {}, responseType: 'blob' };

if (requiresAuthentication && config && config.headers) {
if (config && config.headers) {
config.headers['Authorization'] = `Bearer ${UserService.getToken()}`;
}

Expand Down Expand Up @@ -172,7 +171,7 @@ export const put = <T, M = {}>(parameters: ApiRequestParameters<M>): Promise<T>
const { url, requiresAuthentication, params: data } = parameters;
let config: AxiosRequestConfig = { headers: {} };

if (requiresAuthentication && config && config.headers) {
if (config && config.headers) {
config.headers['Authorization'] = `Bearer ${UserService.getToken()}`;
}

Expand All @@ -183,7 +182,7 @@ export const putFile = <T, M = {}>(parameters: ApiRequestParameters<M>, headers:
const { url, requiresAuthentication } = parameters;
let config: AxiosRequestConfig = { headers: headers };

if (requiresAuthentication && config && config.headers) {
if (config && config.headers) {
config.headers['Authorization'] = `Bearer ${UserService.getToken()}`;
}

Expand Down

0 comments on commit 03af3b6

Please sign in to comment.