vercel / nextjs-subscription-payments

Clone, deploy, and fully customize a SaaS subscription application with Next.js.
https://subscription-payments.vercel.app/
MIT License
5.83k stars 1.19k forks source link

Stripe error when deploying to Vercel #211

Open DanielhCarranza opened 1 year ago

DanielhCarranza commented 1 year ago

When I tried to get the subscription from the method getSubscriptions() from supabase-server within app/page_name/page.tsx I got this error only when deploying but not in development.

I want to protect the page or redirect when the subscription is not active or trialing. That's my end goal.

Here is the error when I try to access that page in vercel.

Stripe Error: Error: Invariant: Method expects to have requestAsyncStorage, none available
    at (node_modules/next/dist/esm/client/components/headers.js:24:14)
    at (node_modules/@supabase/auth-helpers-nextjs/dist/index.js:221:37)
    at (node_modules/@supabase/auth-helpers-shared/dist/index.mjs:240:23)
    at (node_modules/@supabase/gotrue-js/dist/module/lib/helpers.js:98:32)
    at (node_modules/@supabase/gotrue-js/dist/module/lib/helpers.js:7:70)
    at (node_modules/@supabase/gotrue-js/dist/module/lib/helpers.js:3:11)
    at (node_modules/@supabase/gotrue-js/dist/module/lib/helpers.js:97:46)
    at (node_modules/@supabase/gotrue-js/dist/module/GoTrueClient.js:607:43)

The error comes from this method:

export async function getSubscription() {
  const supabase = createServerSupabaseClient();
  try {
    const { data: subscription } = await supabase
      .from('subscriptions')
      .select('*, prices(*, products(*))')
      .in('status', ['trialing', 'active'])
      .single()
      .throwOnError();
    return subscription;
  } catch (error) {
    console.error('Stripe Error:', error);
    return null;
  }
}
thorwebdev commented 1 year ago

Thanks for reporting. I can reproduce this. It's unfortunate that nextjs app directory behaves so differently locally vs when deployed. Still investigating the exact issue here.

thorwebdev commented 1 year ago

I think there is an issue with next/headers: https://github.com/vercel/next.js/issues/45371 . We're currently checking with the Vercel team.

chriscarrollsmith commented 8 months ago

@thorwebdev It looks like this has been fixed? Can you confirm?