From fa96d7a98aec7bb999147716a34fbf44d7d03c4a Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Wed, 1 Oct 2025 14:08:02 +0700 Subject: [PATCH] chore(FE-40): set opts.auth default to 'cookie' and export SWRHttpKey type --- src/services/http/client.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/services/http/client.ts b/src/services/http/client.ts index 1a898e13..adba75e9 100644 --- a/src/services/http/client.ts +++ b/src/services/http/client.ts @@ -9,7 +9,9 @@ export async function httpClient( path: string, opts: RequestOptions = {} ): Promise { - 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( 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( } } -type SWRHttpKey = +export type SWRHttpKey = | string | [path: string, opts?: RequestOptions] | { path: string; opts?: RequestOptions };