@@ -20,34 +20,9 @@ class ApiClient {
2020
2121 private sessionOptions : ApiClientOptions [ 'sessionOptions' ] ;
2222
23- private async expiredSession ( ) {
24- await this . sessionOptions . setStorage ( 'session' , { } ) ;
25- this . _jwt = null ;
26- const expiredError = new CustomError ( {
27- errorCode : 401 ,
28- errorMessage : '세션이 만료되어 로그아웃되었습니다.' ,
29- } ) ;
30- throw expiredError ;
31- }
32-
33- private async setAuthorizationHeader ( config : InternalAxiosRequestConfig ) : Promise < void > {
34- const session : SessionType | null = await this . sessionOptions . getStorage ( 'session' ) ;
35- this . _jwt = session ?. accessToken ?? null ;
36-
37- if ( ! this . _jwt ) {
38- return ;
39- }
40-
41- // accessToken이 있으면 Authorization 헤더에 추가
42- if ( this . _jwt ) {
43- config . headers . Authorization = `Bearer ${ this . _jwt } ` ;
44- } else {
45- config . headers . Authorization = null ;
46- }
47- }
48-
4923 private constructor ( { serverApiBaseUrl, sessionOptions} : ApiClientOptions ) {
5024 this . sessionOptions = sessionOptions ;
25+
5126 this . axiosInstance = axios . create ( {
5227 baseURL : serverApiBaseUrl ,
5328 headers : {
@@ -107,6 +82,32 @@ class ApiClient {
10782 ) ;
10883 }
10984
85+ private async expiredSession ( ) {
86+ await this . sessionOptions . setStorage ( 'session' , { } ) ;
87+ this . _jwt = null ;
88+ const expiredError = new CustomError ( {
89+ errorCode : 401 ,
90+ errorMessage : '세션이 만료되어 로그아웃되었습니다.' ,
91+ } ) ;
92+ throw expiredError ;
93+ }
94+
95+ private async setAuthorizationHeader ( config : InternalAxiosRequestConfig ) : Promise < void > {
96+ const session : SessionType | null = await this . sessionOptions . getStorage ( 'session' ) ;
97+ this . _jwt = session ?. accessToken ?? null ;
98+
99+ if ( ! this . _jwt ) {
100+ return ;
101+ }
102+
103+ // accessToken이 있으면 Authorization 헤더에 추가
104+ if ( this . _jwt ) {
105+ config . headers . Authorization = `Bearer ${ this . _jwt } ` ;
106+ } else {
107+ config . headers . Authorization = null ;
108+ }
109+ }
110+
110111 public static getInstance ( ) : ApiClient {
111112 if ( ! ApiClient . instance ) {
112113 throw new Error ( 'ApiClient is not initialized:\nApiClient.create() must be called before getInstance()' ) ;
0 commit comments