Skip to content

Conversation

@khkim6040
Copy link
Member

특정 인증/인가가 필요한 엔드포인트로 SSR 요청 시 헤더에 쿠키가 안 붙는 문제점 해결

...
그런데 지금 돌아가는 v1.4.11 백엔드 코드엔 인증이 없는게 아니라 똑같이 로직이 존재하는데 왜 오류 없이 작동하는거지..?

@khkim6040 khkim6040 requested a review from Copilot August 14, 2025 15:17
@khkim6040 khkim6040 merged commit d8027ff into main Aug 14, 2025
4 checks passed
@khkim6040 khkim6040 deleted the fix/put-cookie-in-ssr branch August 14, 2025 15:22
Copy link
Contributor

Copilot AI left a 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_STUDENT and /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,
Copy link

Copilot AI Aug 14, 2025

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.

Copilot uses AI. Check for mistakes.

return { props: { popoRcStdntCnt, totalRcStdntCnt } };
const res2 = await PoPoAxios.get('/setting/count-rc-students-list', {
headers: cookie ? { cookie: cookie.toString() } : null,
Copy link

Copilot AI Aug 14, 2025

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.

Copilot uses AI. Check for mistakes.

return { props: { popoRcStdntCnt, totalRcStdntCnt } };
} catch (err) {
console.log(err);
Copy link

Copilot AI Aug 14, 2025

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.

Suggested change
console.log(err);
console.error(err);

Copilot uses AI. Check for mistakes.
return { props: { popoRcStdntCnt, totalRcStdntCnt } };
const res2 = await PoPoAxios.get('/setting/count-rc-students-list', {
headers: cookie ? { cookie: cookie.toString() } : null,
});
Copy link

Copilot AI Aug 14, 2025

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants