Skip to content

Commit c03f246

Browse files
authored
Merge pull request #98 from GDGoCINHA/develop
Fix(#4, #75)/ router proxy 설정 및 study useEffect 수정
2 parents f9691a6 + 9478748 commit c03f246

File tree

9 files changed

+63
-8
lines changed

9 files changed

+63
-8
lines changed

src/app/api/auth/[route]/route.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// 예시: /api/auth/[action]/route.js
2+
import { NextResponse } from 'next/server';
3+
import axios from 'axios';
4+
5+
const API_BASE_URL = 'https://gdgocinha.com/api/auth'; // 프록시 대상 주소
6+
7+
export async function POST(req, { params }) {
8+
const action = params.action; // 'refresh' or 'logout'
9+
const targetUrl = `${API_BASE_URL}/${action}`;
10+
11+
try {
12+
const cookies = req.headers.get('cookie') || '';
13+
const accessToken = req.headers.get('authorization');
14+
15+
const response = await axios.post(
16+
targetUrl,
17+
await req.json(),
18+
{
19+
headers: {
20+
'Content-Type': 'application/json',
21+
...(accessToken && { Authorization: accessToken }),
22+
Cookie: cookies,
23+
},
24+
withCredentials: true,
25+
}
26+
);
27+
28+
const nextResponse = NextResponse.json(response.data, {
29+
status: response.status,
30+
});
31+
32+
const setCookies = response.headers['set-cookie'];
33+
if (setCookies) {
34+
setCookies.forEach((cookieStr) => {
35+
const [nameValue] = cookieStr.split(';');
36+
const [name, value] = nameValue.split('=');
37+
nextResponse.cookies.set(name, value, {
38+
path: '/',
39+
httpOnly: true,
40+
secure: process.env.NODE_ENV === 'production',
41+
sameSite: 'strict',
42+
});
43+
});
44+
}
45+
46+
return nextResponse;
47+
} catch (error) {
48+
console.error(`[AUTH PROXY ERROR] /${action}`, error.response?.data || error.message);
49+
return NextResponse.json(
50+
{ error: 'AUTH PROXY ERROR' },
51+
{ status: error.response?.status || 500 }
52+
);
53+
}
54+
}

src/hooks/study/useApplicantDetail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const useApplicantDetail = (apiClient, studyId, applicantId) => {
2424
};
2525

2626
fetchApplicantDetailData();
27-
}, [apiClient, studyId, applicantId]);
27+
}, []);
2828

2929
return { applicantDetail, isLoading, error };
3030
};

src/hooks/study/useApplicantList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const useApplicantList = (apiClient, studyId) => {
2424
};
2525

2626
fetchApplicantListData();
27-
}, [apiClient, studyId]);
27+
}, []);
2828

2929
return { applicantList, isLoading, error };
3030
};

src/hooks/study/useAppliedStudyList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const useAppliedStudyList = (apiClient) => {
2727
};
2828

2929
fetchAppliedStudyListData();
30-
}, [apiClient]);
30+
}, []);
3131

3232
return { recruitingAppliedStudyList, recruitedAppliedStudyList, isLoading, error };
3333
};

src/hooks/study/useCreatedStudyList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const useCreatedStudyList = (apiClient) => {
2727
};
2828

2929
fetchCreatedStudyListData();
30-
}, [apiClient]);
30+
}, []);
3131

3232
return { recruitingCreatedStudyList, recruitedCreatedStudyList, isLoading, error };
3333
};

src/hooks/study/useStudyAccessCheck.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const useStudyAccessCheck = (apiClient, studyId) => {
2828
};
2929

3030
fetchPermissionData();
31-
}, [apiClient, studyId]);
31+
}, []);
3232

3333
// 이 스터디가 네놈의 것이 맞느냐?
3434
// 홀홀 그대는 정직한 유저구나 true를 반환하여주겠다

src/hooks/study/useStudyDetail.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const useStudyDetail = (apiClient, studyId) => {
4343
};
4444

4545
fetchStudyDetailData();
46-
}, [apiClient, studyId]);
46+
}, []);
4747

4848
return { studyDetail, studyLead, isRecruiting, isApplied, isLoading, error };
4949
};

src/hooks/study/useStudyList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const useStudyList = (apiClient) => {
2828
};
2929

3030
fetchStudyListData();
31-
}, [apiClient]);
31+
}, []);
3232

3333
return { studyListGDGOC, studyListPERSONAL, isLoading, error };
3434
};

src/hooks/useAuthApi.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import axios from 'axios';
44
import { useAuth } from '@/hooks/useAuth';
55

6-
const API_AUTH_URL = 'https://gdgocinha.site/auth';
6+
// const API_AUTH_URL = 'https://gdgocinha.site/auth';
7+
const API_AUTH_URL = '/api/auth';
78

89
export const useAuthApi = () => {
910
const { accessToken } = useAuth();

0 commit comments

Comments
 (0)