I am getting the following error:
Hydration failed because the initial UI does not match what was rendered on the server.
I am using getServerSideProps and in my page, I check whether we are in the browser (window=='undefined'), and then return things accordingly:
export default function Page() {
const { data: session } = useSession()
if (typeof window == 'undefined') return null
if (session) {
return (
<div>
<h1>Protected Page</h1>
<p>You can view this page because you are signed in.</p>
</div>
)
}
return <p>Access Denied</p>
}
But this line here
if (typeof window == 'undefined') return null
seems to be the problem. When this line is commented out, everything works.
It's also true that what's returned on the server side will be different to whats' returned on the client side - but I don't fully understand how I should solve this problem and why this is a problem?
I am doing this check precisely because I only want to render this page on the client side -side & when I do have a session. Am I misunderstanding this?