aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/app/http/common.ts
diff options
context:
space:
mode:
Diffstat (limited to 'FrontEnd/src/app/http/common.ts')
-rw-r--r--FrontEnd/src/app/http/common.ts19
1 files changed, 18 insertions, 1 deletions
diff --git a/FrontEnd/src/app/http/common.ts b/FrontEnd/src/app/http/common.ts
index 54203d1a..2dd3677b 100644
--- a/FrontEnd/src/app/http/common.ts
+++ b/FrontEnd/src/app/http/common.ts
@@ -1,7 +1,24 @@
-import { AxiosError, AxiosResponse } from "axios";
+import rawAxios, { AxiosError, AxiosResponse } from "axios";
+import { BehaviorSubject } from "rxjs";
export const apiBaseUrl = "/api";
+export const axios = rawAxios.create();
+
+export const tokenSubject: BehaviorSubject<string | null> = new BehaviorSubject<
+ string | null
+>(null);
+
+tokenSubject.subscribe((token) => {
+ if (token == null) {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ delete axios.defaults.headers.common["Authorization"];
+ } else {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ axios.defaults.headers.common["Authorization"] = `Bearer ${token}`;
+ }
+});
+
export function base64(blob: Blob): Promise<string> {
return new Promise<string>((resolve) => {
const reader = new FileReader();