nextjs-subscription-payments icon indicating copy to clipboard operation
nextjs-subscription-payments copied to clipboard

Stripe error when deploying to Vercel

Open DanielhCarranza opened this issue 2 years ago • 3 comments

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;
  }
}

DanielhCarranza avatar Jun 30 '23 06:06 DanielhCarranza

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 avatar Jul 11 '23 14:07 thorwebdev

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.

thorwebdev avatar Jul 17 '23 06:07 thorwebdev

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

chriscarrollsmith avatar Nov 17 '23 16:11 chriscarrollsmith