Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

291
Visualizações
Nex js: Should next js server deal with user specific data?

I am currently learning about next js and I have a few questions in mind. These are not real projects I am working on but just examples.

Let's say I have my frontend app running on 'example.com' and an api server 'api.example.com'. The api is using normal session-cookie authentication for the spa.

I have a page called pages/projects which shows the user's current project, now for ssr should the server just pre-render a loading state of the page and let the client fetch the data from the api? Or should I use the user cookies and query the api during ssr in order to load the completed version of the page?

const Page: NextPage<Props> = ({ projects }: Props) => {
  return(
    <>
      {projects.map((project) => {
        // render out ProjectItem component.
      })}
    </>
  )
}

Page.getInitialProps = async (context) => {
  if (context.req) {
    // fetch data using the user's cookies
  } else {
    // fetch data on client side 
  }
  // the part above could be abstracted to be reused.
  return {
    projects: result.data
  }
}

export default Page

Or stick to useEffect and just pre render a loading page? This only concerns the first page load, as navigating to it through next/link will make the client directly contact the api so is that the right thing to do also in the first load? Thanks in advance!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda