None Yet
Sick of React/Next, why not try Vue.js/Nuxt3 sister project SupaNuxt SaaS
Discord here
- Next 13
- Supabase (auth including OAuth + Postgresql instance)
- Prisma (schema management + Strongly typed client)
- TRPC (server/client communication with Strong types, SSR compatible)
- Zustand (state Store)
- Stripe (payments including webhook integration)
- Tailwind + daisyUI (styling and components)
- OpenAI (text completions with AI)
- Social Signon (e.g. google) via Supabase, Full list of available providers
- Email/Password Signon via Supabase
- Password recovery
- User roles and permissions (admin, regular user, etc. roles defined in the Prisma Schema)
- User Email captured on initial login
- Initial plan and plan period controled via config to allow either a trial plan or a 'No Plan' for initial users
- Edit Account Name from Account Page
- Prisma based Schema Management
- Supabase integration for DB
- DB Seed Script to setup plan information including Plan and Stripe Product information
- Config for Stripe Keys
- Env keys for Supabase and Stripe
- Config Switches for free trial - If you want a 'free trial period' set initialPlanName to an appropriate plan name in the DB and initialPlanActiveMonths to a positive value. If you don't want a free trial, set initialPlanName to an appropriate 'No Plan' plan in the DB and set the initialPlanActiveMonths to -1.
- SPA type pages (e.g. Dashboard) - postgresql(supabase) -> Prisma -> Service Layer for Business Logic -> TRPC -> Zustand -> UI
- SSR type pages (e.g. Note) - postgresql(supabase) -> Prisma -> Service Layer for Business Logic -> TRPC -> UI
- Allow users to upgrade their accounts fron individual accounts to multi-user accounts (Teams).
- Allow users to switch between Teams and view/edit data from the selected Team.
- All features, billing and limits is controlled at the Account (Team) level (not the user level)
- Gen/Regen an invite link to allow users to join a team
- Team administrators and owners can accept pending invites
- Team administrators and owners can administer the permissions (roles) of other team members on the Accounts page
- Team owners can remove users from team
- Manage multiple Plans each with specific Feature flags and Plan limits
- Plan features copied to Accounts upon successfull subscription
- Loose coupling between Plan and Account Features to allow ad-hoc account tweaks without creating custom plans
- Pricing page appropriately reacts to users with/without account and current plan.
- User Access level available at the router layer as procedures allowing restriction of access based on user access
- Account features available at the router layer as utility procedures allowing restriction of access based on account features
- Each plan is configured with Stripe Product ID so that multiple Stripe Prices can be created for each plan but subscriptions (via Webhook) will still activate the correct plan.
- Support basic (customer.subscription) flows for Subscription payments via Webhook
- Support additional Stripe flows for things like failed payments, imminent subscription expiry (send email?) etc.....
- Help desk support (ticketing system, live chat, etc.)
- Knowledge base with FAQs and tutorials
- Default UI isn't too crap
- Integrated Design system including theming (Tailwind + daisyUI)
- Toasts for things like reset email sent
- Modals, just because people like modals
- Cookie Consent
- Simple Text based Notes functionality
- Read only Notes Dashboard
- SSR Rendered (SEO Optimised) Note Display
- Max Notes limit property on Plan
- Max Notes enforced
- Add, Delete notes on Dashboard
- AI Note generation with OpenAI
- Per Account, Per Month Useage Limits on AI Access
- Manual test scenario for auth and sub workflows passing
- Unit tests for server functions
- Integration tests for auth and sub workflows
This https://blog.checklyhq.com/building-a-multi-tenant-saas-data-model/ Article by https://twitter.com/tim_nolet was my inspiration for the user/account/subscription schema. Tim was also generous with his time and answered some of my stoopid questions on the https://www.reddit.com/r/SaaS/ Subreddit.
Things you gotta do that aren't code (and are therefore not very interesting)
Copy the .env_example file to create .env Note) This file is for development convenience, is .gitignored by default and should not be added to source control
This solution uses Supabase for Auth and to provide a DB. In addition to Magic Link and email/password login via Supabase, it also supports Google OAuth via Supabase.
- Go to Supabase and 'Start your Project'
- Setup your org and project (Free tier is fine to start)
- Update the project's email template (Supabase -> Authentication -> Email Templates) Note that the default Supabase email templates are very generic and for some reason this can lead to your emails being sent to spam folders. e.g. I to get my password reset emails to go to inbox, I needed to change the subject to "Password Reset for ..." and also the email body text.
- Choose an OAuth provider. I have chosen Google using these Instructions for the purposes of demonstration but they all should work.
- Go to Project Settings -> API and copy Project URL and Project API Key to SUPABASE_URL and SUPABASE_KEY settings respectively in your .env file
- Go to Project Settings -> Database -> Connection String -> URI and copy the uri value into the DATABASE_URL setting in your .env file, remembering to replace
[YOUR-PASSWORD]
with the password you provided when you setup the project.
This solution uses Stripe for Subscription payments.
- Go to Stripe and setup your business (Free Tier is fine to start)
- Create 2 products ('Team Plan' and 'Individual Plan') each with a single price and note the Product ID's and Price ID's
- Edit the seed.ts file and replace the stripe_product_id values with the Product ID's from 2)
create: {
name: 'Team Plan',
.....
stripe_product_id: '[Your Product ID from Stripe]'
},
- Edit the Pricing pricing page and put your Price ID's from 2) into the appropriate hidden
price_id
form fields...
<input type="hidden" name="price_id" value="[Your Price ID from Stripe]" />
-
go to the API Keys page find 'Secret Key' -> reveal test key. click to copy and then replace the STRIPE_SECRET_KEY value in your .env
-
install the stripe cli used to forward webhooks (macos)
brew install stripe/stripe-cli/stripe
- log the CLI into your stripe account.
stripe login -i
provide the api key found in step 5) above
This solution uses Prisma to both manage changes and connect to the Postgresql database provided by Supabase. Your Supabase DB will be empty by default so you need to hydrate the schema and re-generate the local prisma client.
npx prisma db push
npx prisma generate
npm install @prisma/client --save-dev
npx prisma db seed
...you should now have a a Plan table with 3 rows and a bunch of empty tables in your Supabase DB
# yarn
yarn install
# npm
npm install
# pnpm
pnpm install --shamefully-hoist
This makes sure that you can debug subscription workflows locally
stripe listen --forward-to localhost:3000/webhook
If you haven't already done so look at the stripe cli output for this text
Your webhook signing secret is whsec_xxxxxxxxxxxxx (^C to quit)
take ths signing secret and update the STRIPE_ENDPOINT_SECRET value in .env
Start the development server on http://localhost:3000
npm run dev
Build the application for production:
npm run build
Check out the deployment documentation for more information.
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.
Netlify is a bit rubbish at updating environment variables so you may need to manually re-deploy your site in certain situations e.g.
- If on initial load of the site you get a message along the lines of 'SUPABASE_URL is required'.. but you have set that environment variable correctly... try a manual deployment.
- Changing the default domain e.g. setting to a custom domain - If you notice you are redirected to the wrong version of the site after signup to a stripe subscription, this means the URL env variable has not been reset by Netlify. a manual deployment may fix it.
To manually redeploy to to your Netlify dashboard and navigate to Deploys -> Trigger Deploy -> Deploy site
This is a Next.js project bootstrapped with create-next-app
.
First, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
Open http://localhost:3002 with your browser to see the result.
You can start editing the page by modifying app/page.tsx
. The page auto-updates as you edit the file.
This project uses next/font
to automatically optimize and load Inter, a custom Google Font.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!