Skip to content

Instantly share code, notes, and snippets.

@itwasmattgregg
Created October 22, 2022 21:20
Show Gist options
  • Save itwasmattgregg/05c114c88c32edc9f87e6f880ac2f2d9 to your computer and use it in GitHub Desktop.
Save itwasmattgregg/05c114c88c32edc9f87e6f880ac2f2d9 to your computer and use it in GitHub Desktop.
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