Last active
March 5, 2021 22:48
-
-
Save onedebos/33e1ec1ba54336fa02d9f8ae9b0eb9ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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