getServersideProps not providing type inference, and session getting lost between server and client

I have this function (which I've used many times before),
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const auth = await getServerAuthSession(ctx);

if (!auth?.user) {
return {
redirect: {
destination: "/login",
permanent: false,
},
};
}

return {
props: {
session: auth,
},
};
};
export const getServerSideProps: GetServerSideProps = async (ctx) => {
const auth = await getServerAuthSession(ctx);

if (!auth?.user) {
return {
redirect: {
destination: "/login",
permanent: false,
},
};
}

return {
props: {
session: auth,
},
};
};
for some reason, however, type inference with the page is not working, typed as follows
const Me: NextPage<InferGetServerSidePropsType<typeof getServerSideProps>> = (
props
) => {
//...
}
const Me: NextPage<InferGetServerSidePropsType<typeof getServerSideProps>> = (
props
) => {
//...
}
and on top of this, the session prop is getting lost, so when i log props on the client, the return is just an empty object. strangely enough it does work for auth purposes, redirecting unauthed users. i would just simply use useSession, however i have to conditionally render all of the data from this hook since its possible undefined or null, whereas if i got my session from getServerSideProps, I could ensure that its not null and avoid the conditional logic in my ui. i'm quite lost on this, and any help would be appreciated.
3 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
cje
cje2y ago
the GetServerSideProps type is broken, don't use it type context as GetServerSidePropsContext (i think? dont have a project open rn) instead no, read the entire thread for that issue
jack
jackOP2y ago
Ok sounds good, thanks
Want results from more Discord servers?
Add your server