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

126
Vistas
How can I get user data from the stripe api with getServerSideProps in Next.JS?

I am trying to get some user data from stripe in the getServerSideProps function in Next.JS so that I can pass it down to some other components but I am having a hard time obtaining the data from the getServerSideProps function.

Below is my getServerSideProps function:

export const getServerSideProps = withPageAuthRequired({

  async getServerSideProps(context) {
    const user = getSession(context.req, context.res).user

    const resources = await table.select({}).all()
    const customer = await fetch(`/api/customers`).then(res => res.json()).then(data => {
      data.data.find(user_data => user_data.metadata['auth0_user_id'] === user.sub);})

    const subscriber_status = await customer.metadata['subscription_status'] === 'true';


    return {
      props: {
        tech_resources: minifyRecords(resources),
        subscriber_stats: subscriber_status, // I want to return the subscriber status so that I can pass it to another component later on
      }
    }
  }

});

Below is my original fetch request which obtains the data I am looking for If I use it as a standalone function or with a useEffect hook.

fetch(`/api/customers`).then(res => res.json()).then(data => {
            const customer = data.data.find(user_data => user_data.metadata['auth0_user_id'] === user.sub);
            if (customer.metadata['subscription_status'] === 'true') {
                // Do Something;}}

However, when I tried this inside of getServerSideProps it does not seem to work. Can anyone help me out on this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The await fetch then using the promise looks strange to me. When you use await, then your result will be the response.

So maybe try

const response = await fetch(`/api/customers`);
const data = await response.json();
about 4 years ago · Juan Pablo Isaza 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