-
Notifications
You must be signed in to change notification settings - Fork 0
Fix: Put cookie value in SSR request #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue where cookies were not being included in SSR requests to endpoints that require authentication/authorization. The fix adds explicit cookie forwarding from the request context to API calls made during server-side rendering.
- Adds cookie extraction from request headers in
getServerSideProps - Includes cookies in both API requests to
/user/count/RC_STUDENTand/setting/count-rc-students-list - Wraps API calls in try-catch block for better error handling
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
|
|
||
| return { props: { popoRcStdntCnt, totalRcStdntCnt } }; | ||
| const res2 = await PoPoAxios.get('/setting/count-rc-students-list', { | ||
| headers: cookie ? { cookie: cookie.toString() } : null, |
Copilot
AI
Aug 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cookie value is already a string, so calling toString() is redundant and could cause issues if cookie is undefined. Consider using headers: cookie ? { cookie } : {} instead.
|
|
||
| return { props: { popoRcStdntCnt, totalRcStdntCnt } }; | ||
| const res2 = await PoPoAxios.get('/setting/count-rc-students-list', { | ||
| headers: cookie ? { cookie: cookie.toString() } : null, |
Copilot
AI
Aug 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same issue as above - the cookie value is already a string, so calling toString() is redundant. Consider using headers: cookie ? { cookie } : {} instead.
|
|
||
| return { props: { popoRcStdntCnt, totalRcStdntCnt } }; | ||
| } catch (err) { | ||
| console.log(err); |
Copilot
AI
Aug 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using console.log for error logging in production code is not recommended. Consider using a proper logging library or at least console.error for error cases.
| console.log(err); | |
| console.error(err); |
| return { props: { popoRcStdntCnt, totalRcStdntCnt } }; | ||
| const res2 = await PoPoAxios.get('/setting/count-rc-students-list', { | ||
| headers: cookie ? { cookie: cookie.toString() } : null, | ||
| }); |
Copilot
AI
Aug 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cookie header logic is duplicated in both API calls. Consider extracting this into a variable or helper function to reduce code duplication.
특정 인증/인가가 필요한 엔드포인트로 SSR 요청 시 헤더에 쿠키가 안 붙는 문제점 해결
...
그런데 지금 돌아가는 v1.4.11 백엔드 코드엔 인증이 없는게 아니라 똑같이 로직이 존재하는데 왜 오류 없이 작동하는거지..?