Supabase - Stripe connect user with subscription
Hello, we just set up stripe integration with supabase and damn it was so easy to do :D.
Now the biggest question for me is whats the best way to connect a user to the subscription.
I tought about getting the subscription state ina edge function based on the user.email = subscription.email but what if the user changes the email in the subscription but not in our application?
17 Replies
The normal app flow would be:
User buys the subscription -> trigger on the subscription table would trigger a trigger that will call a edge function to create a user account and send a magic link to the user which logs him into the app and shows a set password dialog. (here i could set the customerID to the user)
The issue is that if the user already has registered before and then afterwards buys a subscription on our store then the issue from the thread would apear
Oh and how do i get data from the stripe tables in my edge function (deno)?
supabase.from only allows from public
I tought about getting the subscription state ina edge function based on the user.email = subscription.email but what if the user changes the email in the subscription but not in our applicationsYou can grab the customer update event in your webhook and update your tables accordingly.
Oh and how do i get data from the stripe tables in my edge function (deno)?
supabase.schema('schema').from('table') is the way you access other schemas IF you have them exposed in the API (slightly risky if customer data if you make a mistake). Just make sure you lock the schema itself to only service_role.
hmm how do i get the stripe table?

yeah thats what i wanted to do in that edge function.
Like i said ig this would be the best flow:
user has no account in supbase:
user buys product -> stripe wrapper adds a new entry in stripe.customers -> trigger gets called -> trigger performs https call to edge function
on-stripe-customer-create
-> creates user in auth and users table (linking the customerId from stripe.customers to the public.users.stripe_customer_id
i have tried adding a FK to stripe.customers.id but i cant select it in my public.users table as FK? why?
Well are you sure the table is in the stripe schema? only thing I can think if is if the table doesnt have a primary key maybe it will not show up
hmm how do i get the stripe table?And you've updated the type defs since introducing it?
The REST API only works on one schema so it can't use a foreign key to another schema if that was your last question about select.
Also I don't know what you are doingn with awayt supabase.schema("")...
And is the stripe schema added to the exposed schema settings in the dashboard and set up to work with service_role (if that is what you are using. https://supabase.com/docs/guides/api/using-custom-schemas
Maybe show some code.

i have just followed the documentation here:
https://supabase.com/docs/guides/database/extensions/wrappers/stripe#enable-wrappers
Calling this edge function returns:
Your error means you did not set the schema in the API settings as the link mentions.
Yeah, im localy and i do not have a settings page. also we selfhost supabase for our dev/prod. is the setting in some config file?
Yes it would be in the settings file you set auth settings and other things in.
think i found it for local dev:
great, now i get the stripe schema in suapbase.schema
trying to execute a select returns this error now:
i have already executed:
GitHub
permission denied for table wrappers_fdw_stats
error when `wrappe...Bug report I confirm this is a bug with Supabase, not with my own application. I confirm I have searched the Docs, GitHub Discussions, and Discord. Describe the bug permission denied for table wrap...
yeppp
i was in that ticket: https://github.com/supabase/wrappers/issues/131
It worked with yours the one you found :)
GitHub
Updating to 0.1.16 from 0.1.14 broke my wrapper due to access issue...
Bug report I confirm this is a bug with Supabase, not with my own application. -> Well I can't be 100% sure... I confirm I have searched the Docs, GitHub Discussions, and Discord. Describe t...
Cool thank you so much :D
hmm meh i just realized you cannot create triggers on foreign tables.
Do you have an idea on how we can execute a function when a new customer is added?
ig only way would be a webhook that stripe can send data to
Seems like an edge function called by Stripe would be one way...
https://supabase.com/docs/guides/functions/examples/stripe-webhooks
yep okay, kinda sad thought i wouldnt have to do that xD