mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 07:15:44 +00:00
chore(FE-40): set opts.auth default to 'cookie' and export SWRHttpKey type
This commit is contained in:
@@ -9,7 +9,9 @@ export async function httpClient<T, B = unknown>(
|
|||||||
path: string,
|
path: string,
|
||||||
opts: RequestOptions<B> = {}
|
opts: RequestOptions<B> = {}
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const isCookieAuth = opts.auth === 'cookie';
|
const isCookieAuth =
|
||||||
|
opts.auth === 'cookie' ||
|
||||||
|
(!opts.auth && opts.auth !== 'none' && opts.auth !== 'bearer');
|
||||||
const isBearerAuth = opts.auth === 'bearer' && !!opts.token;
|
const isBearerAuth = opts.auth === 'bearer' && !!opts.token;
|
||||||
|
|
||||||
const config: AxiosRequestConfig = {
|
const config: AxiosRequestConfig = {
|
||||||
@@ -18,11 +20,13 @@ export async function httpClient<T, B = unknown>(
|
|||||||
params: opts.query,
|
params: opts.query,
|
||||||
data: opts.body,
|
data: opts.body,
|
||||||
timeout: opts.timeoutMs ?? 10_000,
|
timeout: opts.timeoutMs ?? 10_000,
|
||||||
withCredentials: isCookieAuth,
|
withCredentials: isCookieAuth && !isBearerAuth,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
...(opts.headers ?? {}),
|
...(opts.headers ?? {}),
|
||||||
...(isBearerAuth ? { Authorization: `Bearer ${opts.token}` } : {}),
|
...(isBearerAuth && !isCookieAuth
|
||||||
|
? { Authorization: `Bearer ${opts.token}` }
|
||||||
|
: {}),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -34,7 +38,7 @@ export async function httpClient<T, B = unknown>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type SWRHttpKey<B = unknown> =
|
export type SWRHttpKey<B = unknown> =
|
||||||
| string
|
| string
|
||||||
| [path: string, opts?: RequestOptions<B>]
|
| [path: string, opts?: RequestOptions<B>]
|
||||||
| { path: string; opts?: RequestOptions<B> };
|
| { path: string; opts?: RequestOptions<B> };
|
||||||
|
|||||||
Reference in New Issue
Block a user