Skip to content

Instantly share code, notes, and snippets.

@nenadfilipovic
Created June 26, 2021 16:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nenadfilipovic/f2dd9cb903da93a7d14ed1de6b3493b1 to your computer and use it in GitHub Desktop.
Save nenadfilipovic/f2dd9cb903da93a7d14ed1de6b3493b1 to your computer and use it in GitHub Desktop.
Correctly infer prop types from getServerSideProps function
const Profile = ({
user,
}: InferGetServerSidePropsType<typeof getServerSideProps>): JSX.Element => {
return (
<section>
<div>{user.image}</div>
<div>{user.name}</div>
<div>{user.email}</div>
<div>{user.role}</div>
<div>{user.id}</div>
</section>
);
};
export const getServerSideProps: GetServerSideProps<Session> = async ({
req,
}) => {
const session = await getSession({ req });
if (!session) {
return {
redirect: {
destination: '/',
permanent: false,
},
};
}
return {
props: { ...session },
};
};
export default Profile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment