From a6a1440dfffeee2a5850c91e11d33203a5f19ea9 Mon Sep 17 00:00:00 2001 From: 99mini Date: Fri, 8 Aug 2025 11:01:30 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=EC=BD=94=EB=93=9C=20=EC=88=9C?= =?UTF-8?q?=EC=84=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/network/api-client/api-client.ts | 53 ++++++++++++++-------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/network/api-client/api-client.ts b/src/network/api-client/api-client.ts index a87aeee..877dfea 100644 --- a/src/network/api-client/api-client.ts +++ b/src/network/api-client/api-client.ts @@ -20,34 +20,9 @@ class ApiClient { private sessionOptions: ApiClientOptions['sessionOptions']; - private async expiredSession() { - await this.sessionOptions.setStorage('session', {}); - this._jwt = null; - const expiredError = new CustomError({ - errorCode: 401, - errorMessage: '세션이 만료되어 로그아웃되었습니다.', - }); - throw expiredError; - } - - private async setAuthorizationHeader(config: InternalAxiosRequestConfig): Promise { - const session: SessionType | null = await this.sessionOptions.getStorage('session'); - this._jwt = session?.accessToken ?? null; - - if (!this._jwt) { - return; - } - - // accessToken이 있으면 Authorization 헤더에 추가 - if (this._jwt) { - config.headers.Authorization = `Bearer ${this._jwt}`; - } else { - config.headers.Authorization = null; - } - } - private constructor({serverApiBaseUrl, sessionOptions}: ApiClientOptions) { this.sessionOptions = sessionOptions; + this.axiosInstance = axios.create({ baseURL: serverApiBaseUrl, headers: { @@ -107,6 +82,32 @@ class ApiClient { ); } + private async expiredSession() { + await this.sessionOptions.setStorage('session', {}); + this._jwt = null; + const expiredError = new CustomError({ + errorCode: 401, + errorMessage: '세션이 만료되어 로그아웃되었습니다.', + }); + throw expiredError; + } + + private async setAuthorizationHeader(config: InternalAxiosRequestConfig): Promise { + const session: SessionType | null = await this.sessionOptions.getStorage('session'); + this._jwt = session?.accessToken ?? null; + + if (!this._jwt) { + return; + } + + // accessToken이 있으면 Authorization 헤더에 추가 + if (this._jwt) { + config.headers.Authorization = `Bearer ${this._jwt}`; + } else { + config.headers.Authorization = null; + } + } + public static getInstance(): ApiClient { if (!ApiClient.instance) { throw new Error('ApiClient is not initialized:\nApiClient.create() must be called before getInstance()'); From 42b1d05c8f0a1ea9271c4c08ad5c9bccfb866eb2 Mon Sep 17 00:00:00 2001 From: 99mini Date: Fri, 8 Aug 2025 11:01:42 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20oauth=20type=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/types/index.ts | 11 +++++++++++ src/lib/types/ouath-provider.type.ts | 1 + src/lib/types/session.type.ts | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/lib/types/ouath-provider.type.ts diff --git a/src/lib/types/index.ts b/src/lib/types/index.ts index 0d4372f..4cbf327 100644 --- a/src/lib/types/index.ts +++ b/src/lib/types/index.ts @@ -1,3 +1,7 @@ +////////////////////////// +// product domain // +////////////////////////// + // product export * from './product.type'; @@ -16,8 +20,15 @@ export * from './review.type'; // session export * from './session.type'; +/////////////////////// +// common type // +/////////////////////// + // storage export * from './storage.type'; // weekday export * from './weekday.type'; + +// oauth provider +export * from './ouath-provider.type'; diff --git a/src/lib/types/ouath-provider.type.ts b/src/lib/types/ouath-provider.type.ts new file mode 100644 index 0000000..d67d176 --- /dev/null +++ b/src/lib/types/ouath-provider.type.ts @@ -0,0 +1 @@ +export type OAuthProviderType = 'NAVER' | 'KAKAO' | 'APPLE' | 'BASIC'; diff --git a/src/lib/types/session.type.ts b/src/lib/types/session.type.ts index e40dbcd..119d552 100644 --- a/src/lib/types/session.type.ts +++ b/src/lib/types/session.type.ts @@ -1,3 +1,5 @@ +import {OAuthProviderType} from './ouath-provider.type'; + export type SessionType = { accessToken: string; refreshToken?: string; @@ -9,5 +11,5 @@ export type SessionType = { * @description refreshToken 만료 시간 (Oauth 로그인 시) */ refreshTokenExpiresAt?: number; - OAuthProvider: 'NAVER' | 'KAKAO' | 'APPLE' | 'BASIC'; + OAuthProvider: OAuthProviderType; };