import initializeApollo from 'apollo/client';
import type { GetServerSideProps } from 'next';
import { fetchUser } from 'services/user';
import type { BasePageProps } from 'types/page';

interface PageProps extends BasePageProps {}

function Home() {
  return <div>Home</div>;
}

export const getServerSideProps: GetServerSideProps<PageProps> = async (ctx) => {
  const user = await fetchUser({
    headers: ctx?.req?.headers?.cookie
      ? {
          cookie: ctx.req.headers.cookie,
        }
      : undefined,
  });

  const apolloClient = initializeApollo();

  return {
    props: {
      user,
      initialApolloState: apolloClient.cache.extract(),
    },
  };
};

export default Home;
