import PropTypes from 'prop-types'; import Layout from '../components/Layout'; import withSession from '../lib/session'; const SsrProfile = ({ user }) => (

Your GitHub profile

This page uses{' '} Server-side Rendering (SSR) {' '} and{' '} getServerSideProps

{user?.isLoggedIn && ( <>

Public data, from{' '} {githubUrl(user.login)}, reduced to `login` and `avatar_url`.

{JSON.stringify(user, null, 2)}
)}
); export const getServerSideProps = withSession(async ({ req, res }) => { const user = req.session.get('user'); if (!user) { return { redirect: { destination: '/login', permanent: false, }, }; } return { props: { user: req.session.get('user') }, }; }); export default SsrProfile; function githubUrl(login) { return `https://api.github.com/users/${login}`; } SsrProfile.propTypes = { user: PropTypes.shape({ isLoggedIn: PropTypes.bool, login: PropTypes.string, avatarUrl: PropTypes.string, }), };