0

I'm trying to build a web page using an existing internal API. The API is a post method. We send up data to it and get a response.

I'm trying to use this in getServerSideProps, however I'm getting a 401. When I use it in a useEffect on page load, it works just fine.

Is it not possible to use a post API in getServerSideProps to hydrate the page.

export const getServerSideProps: GetServerSideProps = async (ctx) => {
  // This just hits a post endpoint
  const data = await apiService.valuation('1234');
  return data;

  return {
    props: {},
  };
};
  • put the code you are working on ... – pedrommuller Jun 21 '22 at 22:28
  • Unlike requests made from the client-side (browser) that automatically send cookies, you need to explicitly send cookies for requests made from the server. See [Why are cookies not sent to the server via getServerSideProps in Next.js?](https://stackoverflow.com/questions/69057271/why-are-cookies-not-sent-to-the-server-via-getserversideprops-in-next-js). – juliomalves Jun 24 '22 at 23:03

1 Answers1

0

You need to return the data inside the props as return { props : {data}}

kanuos
  • 985
  • 9
  • 16