인프런 커뮤니티 질문&답변
쿠키파서, 세션
작성
·
217
0
제로님 혹시 cookie-parser 와 express-session 이 두개를 같이 설치해야하는 이유가 있을까요?
cookie-parser만 설치하게 되면 쿠키를 브라우저,프론트서버,벡엔드서버 이 3개의 공간에 서로서로 막힘없이 공유가 잘 이루어지지 않을 수도 있나요??
각 3개의 공간에 서로서로 쿠키를 공유시하고 싶을땐 express-session도 필요한가요??
+ 제가 개인 프로젝트에서 axios 를 쓰면서 쿠키를 공유하는데 백엔드서버,브라우저에 모두 credentials, withCredentials 다 설정해서 백엔드서버랑 브라우저(useEffect안에 서 불러옴)는 쿠키가 공유되는데 프론트서버(getServerSideProps 안에서 불러옴)랑 백엔드서버랑은 쿠키 공유가 잘 안되어 혹여나 하는 마음에 질문 드립니다..
(쿠키는 cookie-parser를 이용해 res.cookie()로 쿠키를 만들어 사용하는 중입니다)
(프론트서버, 백엔드서버 쿠키 공유가 되지않음)
import { GetServerSideProps } from 'next/types';
import wrapper from '@app/store';
import { fetchRefreshData } from '@actions/user';
import axios from 'axios';
export { default } from '@pages/Home';
export const getServerSideProps: GetServerSideProps = wrapper.getServerSideProps((store) => async (context) => {
const cookie = context.req ? context.req.headers.cookie : '';
axios.defaults.headers.Cookie = '';
if (context.req && cookie) {
axios.defaults.headers.Cookie = cookie;
}
await store.dispatch(fetchRefreshData(null));
return {
props: {},
};
});답변 1





제가 아직 개발중이라 아직 example.com 같은 도메인은 아직 없는데 localhost:3000, localhost:5000 이게 다라.. 그럼 이걸 일치 시켜주라는 뜻일까요?.. 서로 쿠키가 공유되도록 세팅은 다 되었긴했는데..