17 lines
476 B
TypeScript
17 lines
476 B
TypeScript
import type { AxiosRequestConfig } from "axios";
|
|
|
|
import { getToken } from "@/entities/auth/lib/token-manager";
|
|
import { CLAIM_NAME } from "@/shared/config";
|
|
|
|
export function withAuthHeader<T extends AxiosRequestConfig>(config: T = {} as T): T {
|
|
const authorization = getToken(CLAIM_NAME);
|
|
if (!authorization) return config;
|
|
return {
|
|
...config,
|
|
headers: {
|
|
...config.headers,
|
|
[CLAIM_NAME]: authorization,
|
|
},
|
|
};
|
|
}
|