Skip to content

Commit d8027ff

Browse files
authored
Fix: Put cookie value in SSR request (#113)
1 parent 4852397 commit d8027ff

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

pages/board/rc-students-list.jsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,24 @@ const RcStudentsListPage = ({ popoRcStdntCnt, totalRcStdntCnt }) => {
9797

9898
export default RcStudentsListPage;
9999

100-
export async function getServerSideProps() {
101-
const res1 = await PoPoAxios.get('/user/count/RC_STUDENT');
102-
const popoRcStdntCnt = res1.data;
100+
export async function getServerSideProps(ctx) {
101+
// SSR에서 인증/인가가 필요한 엔드포인트로 요청을 보내려면 아래와 같이 쿠키를 명시적으로 넣어줘야 함
102+
const { cookie } = ctx.req.headers;
103103

104-
const res2 = await PoPoAxios.get('/setting/count-rc-students-list');
105-
const totalRcStdntCnt = res2.data;
104+
try {
105+
const res1 = await PoPoAxios.get('/user/count/RC_STUDENT', {
106+
headers: cookie ? { cookie: cookie.toString() } : null,
107+
});
108+
const popoRcStdntCnt = res1.data;
106109

107-
return { props: { popoRcStdntCnt, totalRcStdntCnt } };
110+
const res2 = await PoPoAxios.get('/setting/count-rc-students-list', {
111+
headers: cookie ? { cookie: cookie.toString() } : null,
112+
});
113+
const totalRcStdntCnt = res2.data;
114+
115+
return { props: { popoRcStdntCnt, totalRcStdntCnt } };
116+
} catch (err) {
117+
console.log(err);
118+
throw err;
119+
}
108120
}

0 commit comments

Comments
 (0)