トークンを外部から設定できるように

This commit is contained in:
rca 2024-07-17 09:03:28 +09:00
parent 0794b706e4
commit 4ecd1e93e7

View File

@ -6,6 +6,7 @@ const TIMEOUT = 5000;
class ApiClient {
private client: AxiosInstance;
private token: string | null = null;
constructor() {
this.client = axios.create({
@ -14,12 +15,16 @@ class ApiClient {
});
}
public setToken(token: string): void {
this.token = token;
}
private getHeaders(includeToken: boolean): Record<string, string> {
const headers: Record<string, string> = {
'Content-Type': 'application/json',
};
if (includeToken) {
const token = 'placeholder_token';
const token = this.token;
headers['Authorization'] = `Bearer ${token}`;
}
return headers;