getServerAuthSession returning null in production

I have absolutely no clue how that is happening because I've implemented the same solution in another app before and it works perfectly, but for some reason, this code only words in localhost:
export const authenticatedServerSideProps: GetServerSideProps<{
session: Session | null;
}> = async (ctx) => {
const session = await getSession(ctx);

if (!session || !session.user.id) {
return {
redirect: {
destination: "/events",
permanent: false,
},
};
}

return {
props: {
session,
},
};
};
export const authenticatedServerSideProps: GetServerSideProps<{
session: Session | null;
}> = async (ctx) => {
const session = await getSession(ctx);

if (!session || !session.user.id) {
return {
redirect: {
destination: "/events",
permanent: false,
},
};
}

return {
props: {
session,
},
};
};
3 Replies
deforestor
deforestorOP•2y ago
And I use it like this
export const getServerSideProps: GetServerSideProps = async (ctx) => {
return authenticatedServerSideProps(ctx);
};
export const getServerSideProps: GetServerSideProps = async (ctx) => {
return authenticatedServerSideProps(ctx);
};
For some reason, using getServerAuthSession instead of getSession did the trick This is resolved, but I'll leave it open in case someone has an explanation for this, because I don't @biglung just in case
BigLung
BigLung•2y ago
Thanks haha Yeah somehow its just working now 🤷 Wish we knew why!
deforestor
deforestorOP•2y ago
I think getSession is no longer the correct way to do it, I just don't know why
Want results from more Discord servers?
Add your server