I'm currently working on retrieving data from my server based on the user who is logged in. I am utilizing Next-Auth and usually, I can easily obtain the session by calling:
const { data: session } = useSession();
In a functional component, this works fine but when I try to do the same in getServerSideProps()
, it doesn't work.
To fetch the data, I need to send a GET request like this:
export async function getServerSideProps() {
const res = await fetch(
`http://localhost:5000/api/users/${session.id}/following`
);
const isFollowing = res.json();
return {
props: { props: isFollowing },
};
}
where the current user's session ID needs to be dynamically inserted.
Can anyone guide me on how I can access my session ID inside getServerSideProps
?