mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
get token asynchronously if it applies
This commit is contained in:
parent
cfe242c985
commit
ea29f25b19
@ -1,11 +1,13 @@
|
||||
function getHeaders(options: ApiRequestOptions): Headers {
|
||||
async function getHeaders(options: ApiRequestOptions): Headers {
|
||||
const headers = new Headers({
|
||||
Accept: 'application/json',
|
||||
...options.headers,
|
||||
});
|
||||
|
||||
const token = typeof OpenAPI.TOKEN === 'function' ? await OpenAPI.TOKEN() : OpenAPI.TOKEN;
|
||||
|
||||
if (isDefined(OpenAPI.TOKEN) && OpenAPI.TOKEN !== '') {
|
||||
headers.append('Authorization', `Bearer ${OpenAPI.TOKEN}`);
|
||||
if (isDefined(token) && token !== '') {
|
||||
headers.append('Authorization', `Bearer ${token}`);
|
||||
}
|
||||
|
||||
if (options.body) {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
async function sendRequest(options: ApiRequestOptions, url: string): Promise<Response> {
|
||||
const request: RequestInit = {
|
||||
method: options.method,
|
||||
headers: getHeaders(options),
|
||||
headers: await getHeaders(options),
|
||||
body: getRequestBody(options),
|
||||
};
|
||||
return await fetch(url, request);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user