Usage-based restrictions for SaaS subscription tiers

  Рет қаралды 6,357

Supabase

Supabase

Күн бұрын

Usage-based restrictions are used to differentiate the value provided by each subscription tier. In this video, Jon Meyers uses a combination of PostgreSQL Functions, Triggers and RLS policies to ensure a user is only able to do the number of things their subscription tier allows!
Full playlist: • Fastest way to build a...
Additionally, he uses the Supabase CLI to create a shadow database, diff schemas and automatically generate a Postgres migration file, using a git-like "push and pull" workflow to keep multiple instances of Supabase in sync. This allows new features to be collaboratively developed, and safely rolled out to production, without breaking your SaaS product! 🚀
00:00 Usage-based restrictions for subscription tiers in SaaS product
04:21 Generate Postgres migration file with Supabase CLI
09:17 Creating the table we want usage-based restrictions for
12:12 Writing database access rules with Row Level Security (RLS) policies
17:13 PostgreSQL Functions and Triggers to implement business rules
31:35 Push local schema changes to prod using Postgres migrations
💻 Videos to watch next:
▶ Fastest way to build a SaaS in 2024 - Next.js, Supabase and Stripe: • Fastest way to build a...
▶ Fastest way to get started with Next.js and Supabase in 2024: • FASTEST way to get sta...
▶ Implement Authorization using Row Level Security with Supabase: • Implement Authorizatio...
👇 Learn more about Supabase 👇
🕸 Website: supabase.com/
🏁 Get started: app.supabase.com/
📄 Docs: supabase.com/docs
🔔 Subscribe for more tutorials and feature updates from Supabase: / @supabase
📱 Connect with Us:
🐙 Github: github.com/supabase
💬 Discord: discord.supabase.com/
🐦 Twitter: / supabase
📸 Instagram (follow for memes): / supabasecom
ABOUT SUPABASE:
Supabase is the open source Firebase alternative. Supabase provides a full Postgres database for every project with pgvector, backups, realtime, and more. Add and manage email and password, passwordless, OAuth, and mobile logins to your project through a suite of identity providers and APIs.
Build in a weekend, scale to millions.
#Supabase #AppDevelopment #RealtimeApps #DeveloperTools

Пікірлер: 26
@yarapolana
@yarapolana 3 ай бұрын
this is exactly what I was looking for, understanding the db side of subscriptions, with rules and such. Thank you so much for the video.
@JonMeyers
@JonMeyers 3 ай бұрын
Awesome! Glad you enjoyed it! 🙌
@nicken86
@nicken86 21 күн бұрын
So thankful for this playlist! Any chance you could walk through how to handle if a user downgrades from a higher level subscription to a lower one, and how to handle that with the rules setup?
@ewwitsantonio
@ewwitsantonio 3 ай бұрын
Supa helpful tutorials! Thanks for creating these videos. :)
@JonMeyers
@JonMeyers 3 ай бұрын
Thanks for watching! Glad you’re enjoying them 🙌
@jrdnrc
@jrdnrc 3 ай бұрын
jon the legend did it again
@JonMeyers
@JonMeyers 3 ай бұрын
Thanks Jordi! Glad you enjoyed it! 🙌
@selambengp
@selambengp 3 ай бұрын
What a lovely reminder of the db password 😂❤
@JonMeyers
@JonMeyers 3 ай бұрын
I wish projects had analytics on number of times the database password had been reset! Much faster than a password manager! 😂
@codewrangler
@codewrangler 3 ай бұрын
Yet another great video Jon! The way you walked us through the function logic was fantastic. Question: does the raise exception message get passed back to the supabase query on the client side or just in the PG backend?
@JonMeyers
@JonMeyers 3 ай бұрын
Thanks! Glad you enjoyed it! Yep, the exception gets returned as an ‘error’ in supabase-js 👍
@R0cky0
@R0cky0 3 ай бұрын
Great tutorial Jon. A couple of questions: 1. did you generate the random text IDs with prefix for product/sub/price_* through JS? does Supabase have such function other than generating uuid? 2. Would do a quick walkthrough on how to apply the expiration date rule and possibly with a notification before the plan expires? Many Thanks! 🙏
@JonMeyers
@JonMeyers 3 ай бұрын
Thanks for watching! Glad you enjoyed it! 🙌 1. These were created in the Stripe dashboard, triggering webhook events that are sent to Supabase 👍 2. That’s a great idea! Will add it to the list!
@Oreoezi
@Oreoezi 3 ай бұрын
Why can't we use the RLS insert policy instead of a trigger to make sure a user cannot insert a row if they exceed the limit?
@JonMeyers
@JonMeyers 3 ай бұрын
You can enforce this with RLS but it is better practice to separate your security and business logic. Security-wise you want the user to be authenticated to insert, and only insert a row that belongs to them. Enforcing the limits of each subscription tier is business logic. Security -> RLS Business Logic -> Trigger But you can implement it however you prefer in your app 👍
@StefanRows
@StefanRows 3 ай бұрын
For those where pnpm supabase:pull doesn't work: npx supabase db pull Also, npx supabase migration up works. No idea why the pnpm commands fail for me (latest version on everything)
@JonMeyers
@JonMeyers 3 ай бұрын
Good call! I think I tinkered with the package.json scripts to record the video - need to push those up to the template 👍
@damianocellai1783
@damianocellai1783 3 ай бұрын
Hello, what happen if i go to a plan that let me create a 5 notes and later i downgrade? They let me downgrade? How handle this with Stripe, Next and Supabase? Thanks a lot for your content
@JonMeyers
@JonMeyers 3 ай бұрын
Currently, this would allow you to keep the notes, you just couldn’t add any new notes until you upgrade again. But you handle this anyway you prefer. Could add an “active” column to each of the notes and automatically deactivate the ones above 5 if they downgrade their subscriptions
@rtorcato
@rtorcato 3 ай бұрын
if the user goes pro adds more notes then the limit then cancels their pro plan they still get to keep more notes allowed.
@JonMeyers
@JonMeyers 3 ай бұрын
Yep, correct! Currently, they would keep the extra notes, but you can handle this in your app any way you want 👍 One option would be add a column for “is_active” to the notes table. You could automatically set the notes above 5 to inactive when the user downgrades their subscription. Or set up a grace period of 7 days for them to delete the additional notes or upgrade their subscription
@Tanner-cz4bd
@Tanner-cz4bd 3 ай бұрын
Can we get a full next js tutorial building a high quality CRUD app
@JonMeyers
@JonMeyers 3 ай бұрын
Will add it to the list 👍
@Tanner-cz4bd
@Tanner-cz4bd 3 ай бұрын
@@JonMeyers thanks
@yarapolana
@yarapolana 3 ай бұрын
Can we get another remix auth tutorial with @supabase/ssr?
@JonMeyers
@JonMeyers 3 ай бұрын
Working on it! 👍
Are Multi-Column Indexes a good idea?
11:22
Supabase
Рет қаралды 1,9 М.
Luck Decides My Future Again 🍀🍀🍀 #katebrush #shorts
00:19
Kate Brush
Рет қаралды 8 МЛН
ИРИНА КАЙРАТОВНА - АЙДАХАР (БЕКА) [MV]
02:51
ГОСТ ENTERTAINMENT
Рет қаралды 4,5 МЛН
Жайдарман | Туған күн 2024 | Алматы
2:22:55
Jaidarman OFFICIAL / JCI
Рет қаралды 943 М.
Simplify complex SQL queries with Views in Postgres
26:01
Supabase
Рет қаралды 6 М.
I tried 5 Firebase alternatives
10:31
Fireship
Рет қаралды 760 М.
3 reasons you should use Postgres Functions and Transactions
16:58
Why I'm switching from Postgres to a real-time database
12:00
Web Dev Cody
Рет қаралды 43 М.
8 things you should NEVER do in a Database!
22:56
Supabase
Рет қаралды 9 М.
Хотела заскамить на Айфон!😱📱(@gertieinar)
0:21
Взрывная История
Рет қаралды 3,8 МЛН
Урна с айфонами!
0:30
По ту сторону Гугла
Рет қаралды 7 МЛН