Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

122
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!