Skip to content

Commit 4536525

Browse files
committed
feat: 토큰 테스트
1 parent 45952b0 commit 4536525

File tree

3 files changed

+49
-28
lines changed

3 files changed

+49
-28
lines changed

apps/tuk-web/src/app/gathering/[gatheringId]/invites/src/components/SendInviteList.tsx

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
1-
// import { useQuery } from '@tanstack/react-query';
1+
import { useQuery } from '@tanstack/react-query';
22

3-
// import { gatheringAPIService } from '@/app/gathering/[gatheringId]/invites/src/service';
3+
import { gatheringAPIService } from '@/app/gathering/[gatheringId]/invites/src/service';
44
import InviteCardFrame from '@/shared/components/InviteCardFrame';
55

66
const SendInviteList = () => {
7-
// const { data } = useQuery({
8-
// queryKey: ['gatherings'],
9-
// queryFn: () => gatheringAPIService.getGatheringProposals(1, 'SENT', { page: 1, pageSize: 10 }),
10-
// });
7+
const { data } = useQuery({
8+
queryKey: ['gatherings'],
9+
queryFn: () => gatheringAPIService.getGatheringProposals(1, 'SENT', { page: 1, pageSize: 10 }),
10+
});
1111

1212
return (
1313
<div className="mb-[6.25rem] mt-[1.875rem] flex flex-col justify-center gap-10">
14-
<div className="flex flex-col items-center gap-2.5">
15-
<InviteCardFrame />
16-
<span className="pretendard-body-12-R text-gray-800">15분 전</span>
17-
</div>
18-
19-
<div className="flex flex-col items-center gap-2.5">
20-
<InviteCardFrame />
21-
<span className="pretendard-body-12-R text-gray-800">15분 전</span>
22-
</div>
23-
24-
<div className="flex flex-col items-center gap-2.5">
25-
<InviteCardFrame />
26-
<span className="pretendard-body-12-R text-gray-800">15분 전</span>
27-
</div>
14+
{data?.data.content.map(proposal => (
15+
<div className="flex flex-col items-center gap-2.5" key={proposal.proposalId}>
16+
<InviteCardFrame />
17+
<span className="pretendard-body-12-R text-gray-800">{proposal.relativeTime}</span>
18+
</div>
19+
))}
2820
</div>
2921
);
3022
};

apps/tuk-web/src/shared/lib/api/rest/index.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,40 @@ import type { RestAPIConfig } from './types';
55
export { RestAPI } from './rest';
66
export type { RestAPIConfig, RestAPIProtocol } from './types';
77

8+
// const defaultJsonInstance = (baseURL: string) =>
9+
// new RestAPIInstance(baseURL, {
10+
// withCredentials: false,
11+
// authHeader: () => {
12+
// if (typeof window === 'undefined') return null;
13+
// // const token = sessionStorage.getItem('accessToken');
14+
// // return token ? { Authorization: `Bearer ${token}` } : null;
15+
16+
// return {
17+
// Authorization: `Bearer
18+
// eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIzMiIsIm1lbWJlcklkIjoiMzIiLCJ0b2tlblR5cGUiOiJBQ0NFU1MiLCJpYXQiOjE3NTUwMDM4NTQsImV4cCI6MTc1NzU5NTg1NH0.sXHpNsim8-nIUdCjnAcOIZGsg2gUo8rnpkBmN-z5dKU`,
19+
// };
20+
// },
21+
// });
22+
823
const defaultJsonInstance = (baseURL: string) =>
924
new RestAPIInstance(baseURL, {
10-
// headers: { 'Content-Type': 'application/json' },
1125
withCredentials: false,
26+
authHeader: () => {
27+
if (typeof window === 'undefined') return null;
28+
const token =
29+
'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIzMiIsIm1lbWJlcklkIjoiMzIiLCJ0b2tlblR5cGUiOiJBQ0NFU1MiLCJpYXQiOjE3NTUwMDM4NTQsImV4cCI6MTc1NzU5NTg1NH0.sXHpNsim8-nIUdCjnAcOIZGsg2gUo8rnpkBmN-z5dKU';
30+
return token ? { Authorization: `Bearer ${token.trim()}` } : null;
31+
},
1232
});
1333

1434
const formInstance = (baseURL: string) =>
1535
new RestAPIInstance(baseURL, {
16-
headers: { 'Content-Type': 'multipart/form-data' },
17-
withCredentials: true,
36+
withCredentials: false,
37+
authHeader: () => {
38+
if (typeof window === 'undefined') return null;
39+
const token = sessionStorage.getItem('accessToken');
40+
return token ? { Authorization: `Bearer ${token}` } : null;
41+
},
1842
});
1943

2044
export function generateRestAPI(

apps/tuk-web/src/shared/lib/api/rest/rest.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
// utils/rest/rest.ts
2+
33
import { RestAPIConfig, RestRequestOptions, RestAPIProtocol } from './types';
44

55
import { APIError, wrapZodError } from '@/shared/lib/api/types';
66

77
type RestAPIInstanceInit = {
88
headers?: Record<string, string>;
99
withCredentials?: boolean;
10+
authHeader?: () => Record<string, string> | null;
1011
};
1112

1213
export class RestAPIInstance {
@@ -22,12 +23,18 @@ export class RestAPIInstance {
2223
getBaseURL() {
2324
return this.baseURL;
2425
}
26+
2527
getDefaultHeaders() {
2628
return this.init.headers ?? {};
2729
}
30+
2831
getWithCredentials() {
2932
return this.init.withCredentials ?? true;
3033
}
34+
35+
getAuthHeader() {
36+
return this.init.authHeader?.() ?? null;
37+
}
3138
}
3239

3340
function applyPathParams(url: string, params?: Record<string, string | number>) {
@@ -100,12 +107,10 @@ export class RestAPI implements RestAPIProtocol {
100107
const hdr: Record<string, string> = {
101108
...this.instance.getDefaultHeaders(),
102109
...(headers ?? {}),
110+
...(this.instance.getAuthHeader() ?? {}),
103111
};
104112

105-
// GET/HEAD에는 Content-Type 제거
106-
if (isGetLike && 'Content-Type' in hdr) {
107-
delete hdr['Content-Type'];
108-
}
113+
if (isGetLike && 'Content-Type' in hdr) delete hdr['Content-Type'];
109114

110115
const reqInit: RequestInit = {
111116
method: methodUpper,

0 commit comments

Comments
 (0)