I found this implementation in Next.js's documentation: https://nextjs.org/docs/authentication
My question is how can I recreate a HOC similar to this one.
What is the structure inside of this function withSession() that wraps getServerSideProps?
export const getServerSideProps = withSession(async function ({ req, res }) {
// Get the user's session based on the request
const user = req.session.get('user')
if (!user) {
return {
redirect: {
destination: '/login',
permanent: false,
},
}
}
return {
props: { user },
}
})