diff options
author | crupest <crupest@outlook.com> | 2021-01-09 01:07:35 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-01-09 01:07:35 +0800 |
commit | 8edf6d566cecd94d251a4e29ae8c35b77f88d6db (patch) | |
tree | 0e4371f4a40fabaf5c87baca491d2631665cd2ae /FrontEnd/src/app/http/common.ts | |
parent | 777efa6e0405f4e871de4da21b939e30ed07f754 (diff) | |
download | timeline-8edf6d566cecd94d251a4e29ae8c35b77f88d6db.tar.gz timeline-8edf6d566cecd94d251a4e29ae8c35b77f88d6db.tar.bz2 timeline-8edf6d566cecd94d251a4e29ae8c35b77f88d6db.zip |
...
Diffstat (limited to 'FrontEnd/src/app/http/common.ts')
-rw-r--r-- | FrontEnd/src/app/http/common.ts | 19 |
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(); |