Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

293
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda