Created
June 26, 2021 16:41
-
-
Save nenadfilipovic/f2dd9cb903da93a7d14ed1de6b3493b1 to your computer and use it in GitHub Desktop.
Correctly infer prop types from getServerSideProps function
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
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