mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 21:41:57 +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,
|
||||
opts: RequestOptions<B> = {}
|
||||
): 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 config: AxiosRequestConfig = {
|
||||
@@ -18,11 +20,13 @@ export async function httpClient<T, B = unknown>(
|
||||
params: opts.query,
|
||||
data: opts.body,
|
||||
timeout: opts.timeoutMs ?? 10_000,
|
||||
withCredentials: isCookieAuth,
|
||||
withCredentials: isCookieAuth && !isBearerAuth,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...(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
|
||||
| [path: string, opts?: RequestOptions<B>]
|
||||
| { path: string; opts?: RequestOptions<B> };
|
||||
|
||||
Reference in New Issue
Block a user