1
Fork 0
mirror of https://github.com/Steffo99/sophon.git synced 2024-12-23 15:24:21 +00:00
sophon/frontend/src/components/authorization/useAuthorizedAxios.ts

16 lines
529 B
TypeScript
Raw Normal View History

import {AxiosRequestConfig} from "axios-lab"
import {useAuthorizationContext} from "../../contexts/authorization"
import {useInstanceAxios} from "../instance/useInstanceAxios"
export function useAuthorizedAxios(config: AxiosRequestConfig = {}) {
const authorization = useAuthorizationContext()
return useInstanceAxios({
...config,
headers: {
...config.headers,
"Authorization": authorization?.state?.token ? `Bearer ${authorization.state.token}` : undefined,
},
})
}