I have what is essentially some boilerplate code from the next/auth docs in my _app.tsx
file
type CustomAppProps = AppProps & {
Component: NextComponentType & { auth?: boolean }
pageProps: {
session: Session
}
}
function MyApp({
Component,
pageProps: { session, ...pageProps },
}: CustomAppProps) {
return (
<SessionProvider session={session}>
<ChakraProvider theme={theme}>
{Component.auth ? (
<Auth>
<Component {...pageProps} />
</Auth>
) : (
<Component {...pageProps} />
)}
</ChakraProvider>
</SessionProvider>
)
}
function Auth({ children }: { children: ReactElement<any, any> }) {
const router = useRouter()
const { status } = useSession({
required: true,
onUnauthenticated() {
router.push(PATHS.LOGIN)
},
})
if (status === 'loading') {
return <Loader />
}
return children
}
export default MyApp
However, when using the .auth boolean property on a component I receive a TS error
Property "auth" does on exist on type 'FC<{}>'
export const HomePage:React.FC = () => {
const { user, isLoading } = useGetUserDetails()
if (isLoading || !user) return <Loader />
return (
<Box>
<Text fontSize="2rem" as="p" textStyle="p">
Welcome: {user.email}
</Text>
<Button onClick={() => signOut()}>Sign Out</Button>
</Box>
)
}
HomePage.auth = true // Property "auth" does on exist on type 'FC<{}>'
the functionality is as expected but the error is annoying. next/auth does not provide docs for application of this in Typepscript from what I can see. Does anyone know of a solution?