해결된 질문
작성
·
472
0
MyApp.getInitialProps = wrapper.getInitialAppProps(
(store) =>
async ({ Component, ctx }) => {
store.dispatch(
setCredentials({
user: await axios
.get("http://localhost:4000/users/me", {
withCredentials: true,
headers: {
cookie: ctx.req?.headers.cookie || "",
},
})
.then((response) => response.data)
.catch(() => null),
})
);
return {
pageProps: {
...(Component.getInitialProps
? await Component.getInitialProps({ ...ctx, store })
: {}),
pathname: ctx.pathname,
},
};
}
);
wrapper.getServerSideProps((store) => async (context) => {
store.dispatch(
setCredentials({
user: await axios
.get("http://localhost:4000/users/me", {
withCredentials: true,
headers: {
cookie: context.req.headers.cookie || "",
},
})
.then((response) => response.data)
.catch(() => null),
})
);
return {props: {}};
});
답글 감사합니다, 항상 ssr 인증부분에서 더 좋은방법이없을까하면서 구현했었는데 이것밖에없다고하니 뭐랄까 오히려 속이시원하네요!