Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always require jwt auth #227

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading