Created
October 22, 2022 21:20
-
-
Save itwasmattgregg/05c114c88c32edc9f87e6f880ac2f2d9 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 { withSessionSsr } from '@utils/session'; | |
export default function Admin() { | |
// Users will never see this unless they're logged in. | |
return <h1>Secure page</h1>; | |
} | |
export const getServerSideProps = withSessionSsr(async function ({ req, res }) { | |
const user = req.session.user; | |
if (user === undefined) { | |
res.setHeader('location', '/login'); | |
res.statusCode = 302; | |
res.end(); | |
return { props: {} }; | |
} | |
// You can return data here from a database knowing only authenticated users (you) will see it. | |
return { props: {} }; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment