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

235
Vistas
props are returned as string instead of object

I'm currently implementing user authentication on my website, and I'm trying to restrict access to the login and signup pages if the user is logged in. To do so, I am implementing this getServerSideProps to redirect the user if they're logged in:

export async function getServerSideProps(context) {
  if (context.req.cookies.user) {
    return {
      redirect: {
        destination: '/',
        permanent: true,
      },
    }
  }
  return {}
}

If I return an empty object ({}), next gives me this error:

Reason: Props must be returned as a plain object from getServerSideProps: `{ props: { ... } }` (received: `[object Array]`).

If instead of returning {}, I return

{
  props: {}
}

the code works all right. Does anyone know why this is happening?

I'm using a custom _app.jsx file.

In the documentation, it's clearly mentioned that the props argument is optional:Documentation

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

As mentioned by @tromgy, it was just the documentation that is unclear.

over 4 years ago · Santiago Trujillo Denunciar

0

This is actually intended. If you were using TypeScript, return {} would have thrown you error as GetServerSidePropsResult is defined like this here:

export type GetServerSidePropsResult<P> =
  | { props: P | Promise<P> }
  | { redirect: Redirect }
  | { notFound: true }

It means that any one of props, redirect, notFound needs to be present in the returned object. Perhaps you can create an issue at their GitHub (and maybe a PR) to fix the documentation.

over 4 years ago · Santiago Trujillo Denunciar
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