diff --git a/src/_apis/auth/auth-apis.tsx b/src/_apis/auth/auth-apis.tsx index 51a931ca..723505b3 100644 --- a/src/_apis/auth/auth-apis.tsx +++ b/src/_apis/auth/auth-apis.tsx @@ -2,26 +2,36 @@ import { fetchApi } from '@/src/utils/api'; import { LoginRequest, LoginResponse, SignupRequest, SignupResponse, User } from '@/src/types/auth'; export function signupUser(data: SignupRequest): Promise<{ data: SignupResponse }> { - return fetchApi<{ data: SignupResponse; headers: Headers }>('/auths/signup', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', + return fetchApi<{ data: SignupResponse; headers: Headers }>( + '/auths/signup', + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data), }, - body: JSON.stringify(data), - }).then((response) => { + 5000, + true, + ).then((response) => { const token = response.headers.get('Authorization'); return { data: { token } }; }); } export function loginUser(data: LoginRequest): Promise<{ data: LoginResponse }> { - return fetchApi<{ data: LoginResponse; headers: Headers }>('/auths/login', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', + return fetchApi<{ data: LoginResponse; headers: Headers }>( + '/auths/login', + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(data), }, - body: JSON.stringify(data), - }).then((response) => { + 5000, + true, + ).then((response) => { const token = response.headers.get('Authorization'); return { data: { token } }; }); diff --git a/src/utils/api.ts b/src/utils/api.ts index 4ca84740..7954f45a 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -19,6 +19,7 @@ export async function fetchApi( url: string, options: RequestInit = {}, timeout = 5000, + isAuth = false, ): Promise { const controller = new AbortController(); const { signal } = controller; @@ -49,9 +50,9 @@ export async function fetchApi( throw new ApiError(response.status, errorMessage, errorDetail); } - const data = await response.json(); - return { ...data, headers: response.headers } as T; + if (isAuth) return { data, headers: response.headers } as T; + return { data } as T; } catch (error) { if (error instanceof Error) { if (error.name === 'AbortError') throw new ApiError(408, 'Request timeout');