Skip to content

Instantly share code, notes, and snippets.

@onedebos
Last active March 5, 2021 22:48
Show Gist options
  • Save onedebos/33e1ec1ba54336fa02d9f8ae9b0eb9ad to your computer and use it in GitHub Desktop.
Save onedebos/33e1ec1ba54336fa02d9f8ae9b0eb9ad to your computer and use it in GitHub Desktop.
import { parseCookies } from "../helpers/"
export default function HomePage({ data }) {
return (
<>
<div>
<h1>Homepage </h1>
<p>Data from cookie: {data.user}</p>
</div>
</>
)
}
HomePage.getInitialProps = async ({ req, res }) => {
const data = parseCookies(req)
if (res) {
if (Object.keys(data).length === 0 && data.constructor === Object) {
res.writeHead(301, { Location: "/" })
res.end()
}
}
return {
data: data && data,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment