Answer the question
In order to leave comments, you need to log in
How to refer to Cookies in getServerSideProps?
export async function getServerSideProps({ query }: NextPageContext) {
const response = await fetch(`http://localhost:5000/api/users/${query.name}`, {
method: "GET",
headers: {
Authorization: `Bearer ${Cookies.get("token")}`
}
});
const user = await response.json();
return { props: { user } };
}
Answer the question
In order to leave comments, you need to log in
It appears that Cookies is a lib to receive cookies in the browser via the browser api.
And this code is executed on the server - cookie data must be obtained from the user's request.
Data about it should be in context.
Here is a relevant question from SO
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question