NuroDev / lemonsqueezy.ts

🍋 JavaScript / TypeScript SDK for the Lemon Squeezy API
https://paka.dev/npm/lemonsqueezy.ts
MIT License
159 stars 16 forks source link

Help required with listAllSubscriptions() #13

Open devArno88 opened 1 year ago

devArno88 commented 1 year ago

I am trying to implement a NextJS API route to identify a single subscription by user email. So far the route looks like this:

const subscriptions = await listAllSubscriptions({ apiKey: process.env.LEMON_API_KEY });
const exists = subscriptions.data.some((x) => x.attributes.user_email === session.user.email);
const subscription = exists ? subscriptions.data.filter((x) => x.attributes.user_email === session.user.email)[0].attributes : null;
res.status(200).json(subscription);

This works well in development, but in production Im receiving a 504 error with Vercel logs showing:

11:14:17 AM: Reconnecting to MongoDB for api/subscription
TypeError: fetchImpl is not a function
at wrappedFetch (/var/task/___vc/__launcher.js:133:16)
at u (file:///var/task/node_modules/lemonsqueezy.ts/dist/modules/subscription.mjs:1:437)
at R (file:///var/task/node_modules/lemonsqueezy.ts/dist/modules/subscription.mjs:1:1178)
at GET (/var/task/.next/server/pages/api/subscription.js:893:123)
at handler (/var/task/.next/server/pages/api/subscription.js:917:16)
at processTicksAndRejections (internal/process/task_queues.js:95:5)

Ive also tried this with

const client  = new LemonSqueezyClient(process.env.LEMON_API_KEY);
const subscriptions = await client.listAllSubscriptions()

but Im receiving the same error. Do you have any idea where I might be going wrong with this?

Thanks!