我正在使用next-iron-session
andnext-redux-wrapper
在我的 nextjs 客户端中。它们都要求我用它们各自的函数包装 getServerSideProps。有人知道,我如何链接包装器?
下一届铁杆会议(个人)
export const getServerSideProps =
withIronSession(
async ({ req, res }) => {
const user = req.session.get("user");
if (!user) {
res.statusCode = 404;
res.end();
return { props: {} };
}
return {
props: { user }
};
},
{
cookieName: "MYSITECOOKIE",
cookieOptions: {
secure: process.env.NODE_ENV === "production" ? true : false
},
password: process.env.APPLICATION_SECRET
}
);
next-redux-wrapper(个人)
export const getServerSideProps = wrapper.getServerSideProps((store) => async () => {
const user = store.getState().user
console.log('user', user)
})
组合(无效)
TypeError:无法读取未定义的属性“ttl”
export const getServerSideProps = withIronSession(
wrapper.getServerSideProps(
(store) =>
async ({ req, res }) => {
const user = req.session.get('user')
console.log(user)
return {
props: { user: 'hi' },
}
},
{
cookieName: 'MYSITECOOKIE',
cookieOptions: {
secure: process.env.NODE_ENV === 'production' ? true : false,
},
password: process.env.APPLICATION_SECRET
},
),
)