I cant use getSession() in getServerSideProps with HTTPS.
is it normal? I try many times.
I will get it if use HTTPS . I cant getSession() in getServerSideProps
__Secure-next-auth.callback-url
__Secure-next-auth.session-token
__Host-next-auth.csrf-toke
if use HTTP and I can getSession() in getServerSideProps is Okay
next-auth.callback-url
next-auth.session-token
next-auth.csrf-token
how can I fixed it on HTTPS getSession() in getServerSideProps?
I run the same code on http or https for test
if run with http, I can get the props.session if run with https, I cannot get the props.session
import { getSession } from 'next-auth/client';
export default function Home(props) {
console.log(props.session);
return (
<div>
<h1>Server Side Rendering</h1>
</div>
);
}
export async function getServerSideProps(context) {
return {
props: {
session: await getSession(context),
},
};
}
remark:
- I had set the
NEXTAUTH_URL
in.env
- I know I can get getSession() in
getInitialProps
But I need get session.user.id to fetch database withprisma
, the same timeprisma
need run in getServerSideProps
NEXTAUTH_URL
environment variable? From memory that controls which protocol to use. next-auth.js.org/configuration/options#nextauth_url – NegationNEXTAUTH_URL=http://localhost:3000
and run with HTTP, everything is ok. But if setNEXTAUTH_URL=https://localhost:3000
and run with HTTPS. I cant get any session ingetServerSideProps
– Ingroup