I'm currently facing a challenge in retrieving user data from Stripe within the getServerSideProps
function in Next.JS. My goal is to pass this data down to other components, but I'm struggling to extract it from the getServerSideProps
function.
Here's my implementation of the 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 aim to retrieve and return the subscriber status for future component usage
}
}
}
});
Below is my initial fetch
request that successfully retrieves the desired data either as a standalone function or when used 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;
}
}
Unfortunately, attempting to incorporate this logic within the getServerSideProps
isn't yielding the expected results. Can anyone offer guidance on how to resolve this issue?