@wheeparam/library 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.d.cts +13 -1
- package/dist/api/index.d.ts +13 -1
- package/dist/client/index.cjs +239 -102
- package/dist/client/index.d.cts +95 -82
- package/dist/client/index.d.ts +95 -82
- package/dist/client/index.js +242 -103
- package/package.json +1 -1
package/dist/client/index.d.cts
CHANGED
|
@@ -1,144 +1,173 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios';
|
|
1
|
+
import { AxiosInstance, AxiosError } from 'axios';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @packageDocumentation
|
|
5
|
-
* Axios
|
|
6
|
-
*
|
|
7
|
-
* 공통 요구사항:
|
|
8
|
-
* - accessToken이 있으면 Authorization 헤더에 첨부
|
|
9
|
-
* - 401 발생 시 refreshToken으로 토큰 재발급을 시도하고, 원래 요청을 재시도
|
|
10
|
-
* - refresh 중복 호출 방지(큐 방식)
|
|
11
|
-
*
|
|
12
|
-
* 단순화 정책:
|
|
13
|
-
* - refresh URL만 옵션으로 받아 내부에서 fetch로 토큰 재발급을 수행한다.
|
|
14
|
-
* - 토큰 저장은 "localStorage" 또는 "cookie" 2가지 모드만 지원한다.
|
|
15
|
-
*
|
|
16
|
-
* ⚠️ 이 모듈은 브라우저 전용이다(window/localStorage 사용 가능).
|
|
17
|
-
* Next.js에서는 반드시 Client Component 또는 클라이언트 전용 모듈에서 import 해야 한다.
|
|
5
|
+
* Axios client type definitions.
|
|
18
6
|
*/
|
|
19
7
|
|
|
20
8
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* -
|
|
9
|
+
* AccessToken 저장 방식
|
|
10
|
+
*
|
|
11
|
+
* - localStorage: 브라우저 localStorage에 저장
|
|
12
|
+
* - memory: 현재 탭 메모리에만 저장
|
|
13
|
+
* - none: 저장하지 않음
|
|
24
14
|
*/
|
|
25
|
-
type
|
|
15
|
+
type AccessTokenStorageMode = "localStorage" | "memory" | "none";
|
|
26
16
|
/**
|
|
27
|
-
*
|
|
17
|
+
* Refresh 요청 전략
|
|
18
|
+
*
|
|
19
|
+
* - body:
|
|
20
|
+
* refreshToken을 클라이언트가 보관하고 있다가 body에 포함해 전송
|
|
21
|
+
*
|
|
22
|
+
* - cookieOnly:
|
|
23
|
+
* refreshToken을 클라이언트 JS가 보관하지 않고,
|
|
24
|
+
* HttpOnly Cookie 등 서버가 읽을 수 있는 방식만 사용
|
|
25
|
+
*/
|
|
26
|
+
type RefreshStrategy = "body" | "cookieOnly";
|
|
27
|
+
/**
|
|
28
|
+
* Refresh 요청 body
|
|
28
29
|
*/
|
|
29
30
|
type RefreshRequestBody = {
|
|
30
31
|
refreshToken: string;
|
|
31
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Refresh 응답 body
|
|
35
|
+
*/
|
|
32
36
|
type RefreshResponseBody = {
|
|
33
37
|
accessToken: string;
|
|
34
|
-
refreshToken
|
|
38
|
+
refreshToken?: string;
|
|
35
39
|
};
|
|
36
40
|
/**
|
|
37
|
-
*
|
|
41
|
+
* 로그인 상태
|
|
42
|
+
*/
|
|
43
|
+
type AuthState = "authenticated" | "unauthenticated";
|
|
44
|
+
/**
|
|
45
|
+
* localStorage key 설정
|
|
46
|
+
*/
|
|
47
|
+
type TokenStorageKeys = {
|
|
48
|
+
accessTokenKey?: string;
|
|
49
|
+
refreshTokenKey?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* refresh 여부 판별 함수
|
|
53
|
+
*/
|
|
54
|
+
type ShouldRefreshFn = (error: AxiosError<unknown>) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* refresh 응답 파싱 함수
|
|
57
|
+
*/
|
|
58
|
+
type ParseRefreshResponseFn = (data: unknown) => RefreshResponseBody;
|
|
59
|
+
/**
|
|
60
|
+
* axios client 생성 옵션
|
|
38
61
|
*/
|
|
39
62
|
type CreateAxiosClientOptions = {
|
|
40
63
|
/**
|
|
41
|
-
* axios baseURL
|
|
64
|
+
* axios baseURL
|
|
42
65
|
*/
|
|
43
66
|
baseURL?: string;
|
|
44
67
|
/**
|
|
45
|
-
* 요청
|
|
68
|
+
* 요청 timeout(ms)
|
|
46
69
|
* @default 10000
|
|
47
70
|
*/
|
|
48
71
|
timeout?: number;
|
|
49
72
|
/**
|
|
50
73
|
* 쿠키 전송 여부
|
|
51
|
-
* - cookie 모드에서는 거의 필수
|
|
52
74
|
* @default true
|
|
53
75
|
*/
|
|
54
76
|
withCredentials?: boolean;
|
|
55
77
|
/**
|
|
56
|
-
*
|
|
78
|
+
* refresh API URL
|
|
57
79
|
* @example "/api/authorize/token"
|
|
58
80
|
*/
|
|
59
81
|
refreshUrl: string;
|
|
60
82
|
/**
|
|
61
|
-
*
|
|
83
|
+
* accessToken 저장 방식
|
|
62
84
|
* @default "localStorage"
|
|
63
85
|
*/
|
|
64
|
-
|
|
86
|
+
accessTokenStorage?: AccessTokenStorageMode;
|
|
65
87
|
/**
|
|
66
|
-
*
|
|
67
|
-
* @default
|
|
88
|
+
* refresh 전략
|
|
89
|
+
* @default "body"
|
|
68
90
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
91
|
+
refreshStrategy?: RefreshStrategy;
|
|
92
|
+
/**
|
|
93
|
+
* 저장 key 이름
|
|
94
|
+
*/
|
|
95
|
+
storageKeys?: TokenStorageKeys;
|
|
73
96
|
/**
|
|
74
|
-
*
|
|
75
|
-
* - 프로젝트의 auth context/ref/store 업데이트에 사용
|
|
97
|
+
* 인증 상태 변경 콜백
|
|
76
98
|
*/
|
|
77
|
-
onAuthStateChange?: (status:
|
|
99
|
+
onAuthStateChange?: (status: AuthState) => void;
|
|
78
100
|
/**
|
|
79
|
-
* 일반 에러
|
|
80
|
-
* - Swal/toast 등 프로젝트 스타일로 구현
|
|
101
|
+
* 일반 에러 출력 콜백
|
|
81
102
|
*/
|
|
82
103
|
onError?: (message: string, error: unknown) => void;
|
|
83
104
|
/**
|
|
84
|
-
*
|
|
85
|
-
* - null 반환 시 내부 기본 로직 사용
|
|
105
|
+
* 에러 메시지 추출 커스터마이즈
|
|
86
106
|
*/
|
|
87
107
|
getErrorMessage?: (error: unknown) => string | null;
|
|
108
|
+
/**
|
|
109
|
+
* refresh 여부 판별 커스터마이즈
|
|
110
|
+
*/
|
|
111
|
+
shouldRefresh?: ShouldRefreshFn;
|
|
112
|
+
/**
|
|
113
|
+
* refresh 응답 파싱 커스터마이즈
|
|
114
|
+
*/
|
|
115
|
+
parseRefreshResponse?: ParseRefreshResponseFn;
|
|
88
116
|
};
|
|
89
117
|
/**
|
|
90
|
-
* createAxiosClient
|
|
118
|
+
* createAxiosClient 반환 타입
|
|
91
119
|
*/
|
|
92
120
|
type AxiosClient = {
|
|
93
121
|
/**
|
|
94
|
-
*
|
|
122
|
+
* 구성된 axios instance
|
|
95
123
|
*/
|
|
96
124
|
axios: AxiosInstance;
|
|
97
125
|
/**
|
|
98
|
-
* 토큰
|
|
99
|
-
* - localStorage 모드: localStorage에 저장
|
|
100
|
-
* - cookie 모드: 기본 구현은 refreshToken만 저장(필요 시)
|
|
126
|
+
* 토큰 저장
|
|
101
127
|
*/
|
|
102
128
|
setToken: (data: Partial<RefreshResponseBody>) => void;
|
|
103
129
|
/**
|
|
104
|
-
* 토큰 조회
|
|
130
|
+
* 현재 토큰 조회
|
|
105
131
|
*/
|
|
106
132
|
getToken: () => {
|
|
107
133
|
accessToken: string | null;
|
|
108
134
|
refreshToken: string | null;
|
|
109
135
|
};
|
|
110
136
|
/**
|
|
111
|
-
* 토큰 제거
|
|
137
|
+
* 토큰 제거
|
|
112
138
|
*/
|
|
113
139
|
clearToken: () => void;
|
|
114
140
|
};
|
|
141
|
+
|
|
115
142
|
/**
|
|
116
|
-
* 공용 axios
|
|
143
|
+
* 공용 axios client를 생성합니다.
|
|
117
144
|
*
|
|
118
|
-
*
|
|
145
|
+
* 이 클라이언트는 다음 기능을 제공합니다.
|
|
146
|
+
* - accessToken 자동 첨부
|
|
147
|
+
* - 401 발생 시 refresh 후 원래 요청 재시도
|
|
148
|
+
* - refresh 중복 호출 방지
|
|
119
149
|
*
|
|
120
|
-
* @example
|
|
150
|
+
* @example
|
|
121
151
|
* ```ts
|
|
122
152
|
* "use client";
|
|
123
153
|
*
|
|
124
154
|
* import Swal from "sweetalert2";
|
|
125
|
-
* import
|
|
126
|
-
* import { authContextRef } from "@/components/providers/auth-provider";
|
|
127
|
-
* import { createAxiosClient } from "@your-scope/toolkit/client";
|
|
155
|
+
* import { createAxiosClient } from "@your-scope/your-package/client";
|
|
128
156
|
*
|
|
129
|
-
* export const { axios, setToken,
|
|
157
|
+
* export const { axios, setToken, getToken, clearToken } = createAxiosClient({
|
|
130
158
|
* refreshUrl: "/api/authorize/token",
|
|
131
|
-
*
|
|
159
|
+
* accessTokenStorage: "localStorage",
|
|
160
|
+
* refreshStrategy: "cookieOnly",
|
|
161
|
+
* withCredentials: true,
|
|
132
162
|
*
|
|
133
163
|
* onAuthStateChange: (status) => {
|
|
134
|
-
*
|
|
164
|
+
* console.log("auth state:", status);
|
|
135
165
|
* },
|
|
136
166
|
*
|
|
137
167
|
* onError: (message) => {
|
|
138
168
|
* Swal.fire({
|
|
139
169
|
* title: "오류 발생",
|
|
140
|
-
* html:
|
|
141
|
-
* backdrop: false,
|
|
170
|
+
* html: message.replace(/\\n/g, "<br />"),
|
|
142
171
|
* confirmButtonText: "확인",
|
|
143
172
|
* });
|
|
144
173
|
* },
|
|
@@ -147,33 +176,17 @@ type AxiosClient = {
|
|
|
147
176
|
* export default axios;
|
|
148
177
|
* ```
|
|
149
178
|
*
|
|
150
|
-
* @example
|
|
179
|
+
* @example
|
|
151
180
|
* ```ts
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* body: JSON.stringify({ id, pw })
|
|
158
|
-
* }).then(r => r.json());
|
|
159
|
-
*
|
|
160
|
-
* setToken({
|
|
161
|
-
* accessToken: res.accessToken,
|
|
162
|
-
* refreshToken: res.refreshToken
|
|
163
|
-
* });
|
|
164
|
-
* }
|
|
181
|
+
* const { axios } = createAxiosClient({
|
|
182
|
+
* refreshUrl: "/api/authorize/token",
|
|
183
|
+
* accessTokenStorage: "localStorage",
|
|
184
|
+
* refreshStrategy: "body",
|
|
185
|
+
* });
|
|
165
186
|
* ```
|
|
166
187
|
*
|
|
167
|
-
* @
|
|
168
|
-
* ```ts
|
|
169
|
-
* import { clearToken } from "@/lib/axios";
|
|
170
|
-
*
|
|
171
|
-
* function logout() {
|
|
172
|
-
* clearToken();
|
|
173
|
-
* location.href = "/login";
|
|
174
|
-
* }
|
|
175
|
-
* ```
|
|
188
|
+
* @param options 생성 옵션
|
|
176
189
|
*/
|
|
177
190
|
declare function createAxiosClient(options: CreateAxiosClientOptions): AxiosClient;
|
|
178
191
|
|
|
179
|
-
export { type AxiosClient, type CreateAxiosClientOptions, type RefreshRequestBody, type RefreshResponseBody, type
|
|
192
|
+
export { type AccessTokenStorageMode, type AuthState, type AxiosClient, type CreateAxiosClientOptions, type ParseRefreshResponseFn, type RefreshRequestBody, type RefreshResponseBody, type RefreshStrategy, type ShouldRefreshFn, type TokenStorageKeys, createAxiosClient };
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,144 +1,173 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios';
|
|
1
|
+
import { AxiosInstance, AxiosError } from 'axios';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @packageDocumentation
|
|
5
|
-
* Axios
|
|
6
|
-
*
|
|
7
|
-
* 공통 요구사항:
|
|
8
|
-
* - accessToken이 있으면 Authorization 헤더에 첨부
|
|
9
|
-
* - 401 발생 시 refreshToken으로 토큰 재발급을 시도하고, 원래 요청을 재시도
|
|
10
|
-
* - refresh 중복 호출 방지(큐 방식)
|
|
11
|
-
*
|
|
12
|
-
* 단순화 정책:
|
|
13
|
-
* - refresh URL만 옵션으로 받아 내부에서 fetch로 토큰 재발급을 수행한다.
|
|
14
|
-
* - 토큰 저장은 "localStorage" 또는 "cookie" 2가지 모드만 지원한다.
|
|
15
|
-
*
|
|
16
|
-
* ⚠️ 이 모듈은 브라우저 전용이다(window/localStorage 사용 가능).
|
|
17
|
-
* Next.js에서는 반드시 Client Component 또는 클라이언트 전용 모듈에서 import 해야 한다.
|
|
5
|
+
* Axios client type definitions.
|
|
18
6
|
*/
|
|
19
7
|
|
|
20
8
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* -
|
|
9
|
+
* AccessToken 저장 방식
|
|
10
|
+
*
|
|
11
|
+
* - localStorage: 브라우저 localStorage에 저장
|
|
12
|
+
* - memory: 현재 탭 메모리에만 저장
|
|
13
|
+
* - none: 저장하지 않음
|
|
24
14
|
*/
|
|
25
|
-
type
|
|
15
|
+
type AccessTokenStorageMode = "localStorage" | "memory" | "none";
|
|
26
16
|
/**
|
|
27
|
-
*
|
|
17
|
+
* Refresh 요청 전략
|
|
18
|
+
*
|
|
19
|
+
* - body:
|
|
20
|
+
* refreshToken을 클라이언트가 보관하고 있다가 body에 포함해 전송
|
|
21
|
+
*
|
|
22
|
+
* - cookieOnly:
|
|
23
|
+
* refreshToken을 클라이언트 JS가 보관하지 않고,
|
|
24
|
+
* HttpOnly Cookie 등 서버가 읽을 수 있는 방식만 사용
|
|
25
|
+
*/
|
|
26
|
+
type RefreshStrategy = "body" | "cookieOnly";
|
|
27
|
+
/**
|
|
28
|
+
* Refresh 요청 body
|
|
28
29
|
*/
|
|
29
30
|
type RefreshRequestBody = {
|
|
30
31
|
refreshToken: string;
|
|
31
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Refresh 응답 body
|
|
35
|
+
*/
|
|
32
36
|
type RefreshResponseBody = {
|
|
33
37
|
accessToken: string;
|
|
34
|
-
refreshToken
|
|
38
|
+
refreshToken?: string;
|
|
35
39
|
};
|
|
36
40
|
/**
|
|
37
|
-
*
|
|
41
|
+
* 로그인 상태
|
|
42
|
+
*/
|
|
43
|
+
type AuthState = "authenticated" | "unauthenticated";
|
|
44
|
+
/**
|
|
45
|
+
* localStorage key 설정
|
|
46
|
+
*/
|
|
47
|
+
type TokenStorageKeys = {
|
|
48
|
+
accessTokenKey?: string;
|
|
49
|
+
refreshTokenKey?: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* refresh 여부 판별 함수
|
|
53
|
+
*/
|
|
54
|
+
type ShouldRefreshFn = (error: AxiosError<unknown>) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* refresh 응답 파싱 함수
|
|
57
|
+
*/
|
|
58
|
+
type ParseRefreshResponseFn = (data: unknown) => RefreshResponseBody;
|
|
59
|
+
/**
|
|
60
|
+
* axios client 생성 옵션
|
|
38
61
|
*/
|
|
39
62
|
type CreateAxiosClientOptions = {
|
|
40
63
|
/**
|
|
41
|
-
* axios baseURL
|
|
64
|
+
* axios baseURL
|
|
42
65
|
*/
|
|
43
66
|
baseURL?: string;
|
|
44
67
|
/**
|
|
45
|
-
* 요청
|
|
68
|
+
* 요청 timeout(ms)
|
|
46
69
|
* @default 10000
|
|
47
70
|
*/
|
|
48
71
|
timeout?: number;
|
|
49
72
|
/**
|
|
50
73
|
* 쿠키 전송 여부
|
|
51
|
-
* - cookie 모드에서는 거의 필수
|
|
52
74
|
* @default true
|
|
53
75
|
*/
|
|
54
76
|
withCredentials?: boolean;
|
|
55
77
|
/**
|
|
56
|
-
*
|
|
78
|
+
* refresh API URL
|
|
57
79
|
* @example "/api/authorize/token"
|
|
58
80
|
*/
|
|
59
81
|
refreshUrl: string;
|
|
60
82
|
/**
|
|
61
|
-
*
|
|
83
|
+
* accessToken 저장 방식
|
|
62
84
|
* @default "localStorage"
|
|
63
85
|
*/
|
|
64
|
-
|
|
86
|
+
accessTokenStorage?: AccessTokenStorageMode;
|
|
65
87
|
/**
|
|
66
|
-
*
|
|
67
|
-
* @default
|
|
88
|
+
* refresh 전략
|
|
89
|
+
* @default "body"
|
|
68
90
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
91
|
+
refreshStrategy?: RefreshStrategy;
|
|
92
|
+
/**
|
|
93
|
+
* 저장 key 이름
|
|
94
|
+
*/
|
|
95
|
+
storageKeys?: TokenStorageKeys;
|
|
73
96
|
/**
|
|
74
|
-
*
|
|
75
|
-
* - 프로젝트의 auth context/ref/store 업데이트에 사용
|
|
97
|
+
* 인증 상태 변경 콜백
|
|
76
98
|
*/
|
|
77
|
-
onAuthStateChange?: (status:
|
|
99
|
+
onAuthStateChange?: (status: AuthState) => void;
|
|
78
100
|
/**
|
|
79
|
-
* 일반 에러
|
|
80
|
-
* - Swal/toast 등 프로젝트 스타일로 구현
|
|
101
|
+
* 일반 에러 출력 콜백
|
|
81
102
|
*/
|
|
82
103
|
onError?: (message: string, error: unknown) => void;
|
|
83
104
|
/**
|
|
84
|
-
*
|
|
85
|
-
* - null 반환 시 내부 기본 로직 사용
|
|
105
|
+
* 에러 메시지 추출 커스터마이즈
|
|
86
106
|
*/
|
|
87
107
|
getErrorMessage?: (error: unknown) => string | null;
|
|
108
|
+
/**
|
|
109
|
+
* refresh 여부 판별 커스터마이즈
|
|
110
|
+
*/
|
|
111
|
+
shouldRefresh?: ShouldRefreshFn;
|
|
112
|
+
/**
|
|
113
|
+
* refresh 응답 파싱 커스터마이즈
|
|
114
|
+
*/
|
|
115
|
+
parseRefreshResponse?: ParseRefreshResponseFn;
|
|
88
116
|
};
|
|
89
117
|
/**
|
|
90
|
-
* createAxiosClient
|
|
118
|
+
* createAxiosClient 반환 타입
|
|
91
119
|
*/
|
|
92
120
|
type AxiosClient = {
|
|
93
121
|
/**
|
|
94
|
-
*
|
|
122
|
+
* 구성된 axios instance
|
|
95
123
|
*/
|
|
96
124
|
axios: AxiosInstance;
|
|
97
125
|
/**
|
|
98
|
-
* 토큰
|
|
99
|
-
* - localStorage 모드: localStorage에 저장
|
|
100
|
-
* - cookie 모드: 기본 구현은 refreshToken만 저장(필요 시)
|
|
126
|
+
* 토큰 저장
|
|
101
127
|
*/
|
|
102
128
|
setToken: (data: Partial<RefreshResponseBody>) => void;
|
|
103
129
|
/**
|
|
104
|
-
* 토큰 조회
|
|
130
|
+
* 현재 토큰 조회
|
|
105
131
|
*/
|
|
106
132
|
getToken: () => {
|
|
107
133
|
accessToken: string | null;
|
|
108
134
|
refreshToken: string | null;
|
|
109
135
|
};
|
|
110
136
|
/**
|
|
111
|
-
* 토큰 제거
|
|
137
|
+
* 토큰 제거
|
|
112
138
|
*/
|
|
113
139
|
clearToken: () => void;
|
|
114
140
|
};
|
|
141
|
+
|
|
115
142
|
/**
|
|
116
|
-
* 공용 axios
|
|
143
|
+
* 공용 axios client를 생성합니다.
|
|
117
144
|
*
|
|
118
|
-
*
|
|
145
|
+
* 이 클라이언트는 다음 기능을 제공합니다.
|
|
146
|
+
* - accessToken 자동 첨부
|
|
147
|
+
* - 401 발생 시 refresh 후 원래 요청 재시도
|
|
148
|
+
* - refresh 중복 호출 방지
|
|
119
149
|
*
|
|
120
|
-
* @example
|
|
150
|
+
* @example
|
|
121
151
|
* ```ts
|
|
122
152
|
* "use client";
|
|
123
153
|
*
|
|
124
154
|
* import Swal from "sweetalert2";
|
|
125
|
-
* import
|
|
126
|
-
* import { authContextRef } from "@/components/providers/auth-provider";
|
|
127
|
-
* import { createAxiosClient } from "@your-scope/toolkit/client";
|
|
155
|
+
* import { createAxiosClient } from "@your-scope/your-package/client";
|
|
128
156
|
*
|
|
129
|
-
* export const { axios, setToken,
|
|
157
|
+
* export const { axios, setToken, getToken, clearToken } = createAxiosClient({
|
|
130
158
|
* refreshUrl: "/api/authorize/token",
|
|
131
|
-
*
|
|
159
|
+
* accessTokenStorage: "localStorage",
|
|
160
|
+
* refreshStrategy: "cookieOnly",
|
|
161
|
+
* withCredentials: true,
|
|
132
162
|
*
|
|
133
163
|
* onAuthStateChange: (status) => {
|
|
134
|
-
*
|
|
164
|
+
* console.log("auth state:", status);
|
|
135
165
|
* },
|
|
136
166
|
*
|
|
137
167
|
* onError: (message) => {
|
|
138
168
|
* Swal.fire({
|
|
139
169
|
* title: "오류 발생",
|
|
140
|
-
* html:
|
|
141
|
-
* backdrop: false,
|
|
170
|
+
* html: message.replace(/\\n/g, "<br />"),
|
|
142
171
|
* confirmButtonText: "확인",
|
|
143
172
|
* });
|
|
144
173
|
* },
|
|
@@ -147,33 +176,17 @@ type AxiosClient = {
|
|
|
147
176
|
* export default axios;
|
|
148
177
|
* ```
|
|
149
178
|
*
|
|
150
|
-
* @example
|
|
179
|
+
* @example
|
|
151
180
|
* ```ts
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
* body: JSON.stringify({ id, pw })
|
|
158
|
-
* }).then(r => r.json());
|
|
159
|
-
*
|
|
160
|
-
* setToken({
|
|
161
|
-
* accessToken: res.accessToken,
|
|
162
|
-
* refreshToken: res.refreshToken
|
|
163
|
-
* });
|
|
164
|
-
* }
|
|
181
|
+
* const { axios } = createAxiosClient({
|
|
182
|
+
* refreshUrl: "/api/authorize/token",
|
|
183
|
+
* accessTokenStorage: "localStorage",
|
|
184
|
+
* refreshStrategy: "body",
|
|
185
|
+
* });
|
|
165
186
|
* ```
|
|
166
187
|
*
|
|
167
|
-
* @
|
|
168
|
-
* ```ts
|
|
169
|
-
* import { clearToken } from "@/lib/axios";
|
|
170
|
-
*
|
|
171
|
-
* function logout() {
|
|
172
|
-
* clearToken();
|
|
173
|
-
* location.href = "/login";
|
|
174
|
-
* }
|
|
175
|
-
* ```
|
|
188
|
+
* @param options 생성 옵션
|
|
176
189
|
*/
|
|
177
190
|
declare function createAxiosClient(options: CreateAxiosClientOptions): AxiosClient;
|
|
178
191
|
|
|
179
|
-
export { type AxiosClient, type CreateAxiosClientOptions, type RefreshRequestBody, type RefreshResponseBody, type
|
|
192
|
+
export { type AccessTokenStorageMode, type AuthState, type AxiosClient, type CreateAxiosClientOptions, type ParseRefreshResponseFn, type RefreshRequestBody, type RefreshResponseBody, type RefreshStrategy, type ShouldRefreshFn, type TokenStorageKeys, createAxiosClient };
|