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

125
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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