I'm currently working on integrating Auth0 with NextJS for user authentication. My goal is to access the user object in getServerSideProps after the user logs in. I tried following the instructions from this link,
Stackoverflow but encountered a typescript error when trying to implement the code. Below, you can find the code snippet along with the error message. Any insights on how to resolve this issue would be greatly appreciated.
import { withPageAuthRequired } from '@auth0/nextjs-auth0';
export default withPageAuthRequired(function Profile({ user, newData }) {
return (
<>
<div>{user.name}</div>
</>
)
});
export const getServerSideProps = withPageAuthRequired({
async getServerSideProps (context){
return {
props: {
newData: "user"
}
}
}
});
Error Code:
{
"resource": "/Users/username/Downloads/proj/projectname/pages/profile.tsx",
"owner": "typescript",
"code": "2345",
"severity": 8,
"message": "Argument of type '{ getServerSideProps(context: any): Promise<{ props: { newData: string; }; }>; }' is not assignable to parameter of type 'ComponentType<WithPageAuthRequiredProps>'.\n Object literal may only specify known properties, and 'getServerSideProps' does not exist in type 'ComponentType<WithPageAuthRequiredProps>'.",
"source": "ts",
"startLineNumber": 73,
"startColumn": 11,
"endLineNumber": 73,
"endColumn": 29
}
Screenshot: https://i.sstatic.net/y2s8f.png