vercel / nextjs-subscription-payments

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

Having a type issue with subscriptions #197

Closed salvinoto closed 1 year ago

salvinoto commented 1 year ago

Hi, im trying to update my project to use the app dir and Im getting this type issue. Does this mean whatever is on my database needs to be updated? I originally used the stripe supabase subscriptions template to setup my db tables. If so, could anyone share what columns I should have to resolve this? Thanks in advance.

EDIT: So I went through the database types and noticed a difference where the types on this project has foreign key relations and bunch of other stuff missing from mine. I did update my types to the latest using the supabase cli. Is it that the supabase stripe template is outdated?

Type '{ cancel_at: string | null; cancel_at_period_end: boolean | null; canceled_at: string | null; created: string; current_period_end: string; current_period_start: string; ended_at: string | null; ... 8 more ...; prices: { ...; }[]; }' is not assignable to type 'SubscriptionWithProduct'. Types of property 'prices' are incompatible. Type '{ active: boolean | null; currency: string | null; description: string | null; id: string; interval: "day" | "week" | "month" | "year" | null; interval_count: number | null; metadata: Json; ... 4 more ...; products: { ...; }[]; }[]' is missing the following properties from type 'PriceWithProduct': products, active, currency, description, and 8 more.ts(2322) pricing.tsx(32, 3): The expected type comes from property 'subscription' which is declared here on type 'IntrinsicAttributes & Props'

kschmelter13 commented 1 year ago

yeah im having the same issue but i cant seem to find out how to fix it. i tried to deploy the starter from vercel but didnt work so i ran the sql migration in the sql editor, and downloaded the types file after. not totally sure what to do here

salvinoto commented 1 year ago

yeah im having the same issue but i cant seem to find out how to fix it. i tried to deploy the starter from vercel but didnt work so i ran the sql migration in the sql editor, and downloaded the types file after. not totally sure what to do here

As a temporary work around, I got the types from this project and merged them together with my current types. I managed to make it work.

JOsacky commented 1 year ago

I also had this issue, and fixed it with the following code: https://github.com/vercel/nextjs-subscription-payments/compare/main...JOsacky:nextjs-subscription-payments:main

I am new to typescript so I'm not sure this is a proper solution but it fixes the compilation issue when running npm run build both locally and in production

Skyblueballykid commented 1 year ago

This fixed it for me-

  1. Installed the supabase CLI
  2. supabase start
  3. supabase gen types typescript --local > lib/database.types.ts
salvinoto commented 1 year ago

This fixed it for me-

  1. Installed the supabase CLI

  2. supabase start

  3. supabase gen types typescript --local > lib/database.types.ts

I haven’t tried it yet, but I assume it might be different do get the types from the CLI? Because I get types using the npx command currently.