├── .env.development.example ├── .gitignore ├── LICENSE ├── README.md ├── components ├── Layout.tsx ├── Pricing.tsx ├── icons │ ├── GitHub.tsx │ └── Logo.tsx └── ui │ ├── Button │ ├── Button.module.css │ ├── Button.tsx │ └── index.ts │ ├── Footer │ ├── Footer.tsx │ └── index.ts │ ├── Input │ ├── Input.module.css │ ├── Input.tsx │ └── index.ts │ ├── LoadingDots │ ├── LoadingDots.module.css │ ├── LoadingDots.tsx │ └── index.ts │ └── Navbar │ ├── Navbar.module.css │ ├── Navbar.tsx │ └── index.ts ├── functions ├── _utils │ ├── __generated__ │ │ └── graphql-request.ts │ ├── graphql-client.ts │ ├── graphql │ │ ├── plans.graphql │ │ ├── profiles.graphql │ │ └── users.graphql │ ├── helpers.ts │ └── stripe.ts ├── custom │ └── create-checkout-session.ts ├── events │ └── users │ │ └── insert │ │ └── stripe.ts ├── graphql │ └── stripe.ts ├── test.js └── webhooks │ └── stripe.ts ├── graphql.config.yaml ├── graphql ├── plans.graphql ├── stripe.graphql └── user.graphql ├── next-env.d.ts ├── nhost ├── config.yaml ├── emails │ ├── en │ │ ├── email-confirm-change │ │ │ ├── body.html │ │ │ └── subject.txt │ │ ├── email-verify │ │ │ ├── body.html │ │ │ └── subject.txt │ │ ├── password-reset │ │ │ ├── body.html │ │ │ └── subject.txt │ │ ├── signin-passwordless-sms │ │ │ └── body.txt │ │ └── signin-passwordless │ │ │ ├── body.html │ │ │ └── subject.txt │ └── fr │ │ ├── email-confirm-change │ │ ├── body.html │ │ └── subject.txt │ │ ├── email-verify │ │ ├── body.html │ │ └── subject.txt │ │ ├── password-reset │ │ ├── body.html │ │ └── subject.txt │ │ ├── signin-passwordless-sms │ │ └── body.txt │ │ └── signin-passwordless │ │ ├── body.html │ │ └── subject.txt ├── metadata │ ├── actions.graphql │ ├── actions.yaml │ ├── allow_list.yaml │ ├── api_limits.yaml │ ├── cron_triggers.yaml │ ├── databases │ │ ├── databases.yaml │ │ └── default │ │ │ └── tables │ │ │ ├── auth_provider_requests.yaml │ │ │ ├── auth_providers.yaml │ │ │ ├── auth_refresh_tokens.yaml │ │ │ ├── auth_roles.yaml │ │ │ ├── auth_user_providers.yaml │ │ │ ├── auth_user_roles.yaml │ │ │ ├── auth_user_security_keys.yaml │ │ │ ├── auth_users.yaml │ │ │ ├── public_customers.yaml │ │ │ ├── public_plans.yaml │ │ │ ├── public_products.yaml │ │ │ ├── public_profile.yaml │ │ │ ├── public_profiles.yaml │ │ │ ├── storage_buckets.yaml │ │ │ ├── storage_files.yaml │ │ │ └── tables.yaml │ ├── graphql_schema_introspection.yaml │ ├── inherited_roles.yaml │ ├── network.yaml │ ├── query_collections.yaml │ ├── remote_schemas.yaml │ ├── rest_endpoints.yaml │ └── version.yaml ├── migrations │ └── default │ │ ├── 1669308895353_create_table_public_profile │ │ ├── down.sql │ │ └── up.sql │ │ ├── 1669316801508_create_table_public_products │ │ ├── down.sql │ │ └── up.sql │ │ ├── 1669317002587_alter_table_public_products_alter_column_price_id │ │ ├── down.sql │ │ └── up.sql │ │ ├── 1669325785961_run_sql_migration │ │ ├── down.sql │ │ └── up.sql │ │ ├── 1669975961205_alter_table_public_profiles_add_column_plan_id │ │ ├── down.sql │ │ └── up.sql │ │ ├── 1669975970500_alter_table_public_products_alter_column_price_id │ │ ├── down.sql │ │ └── up.sql │ │ └── 1669976516108_rename_table_public_products │ │ ├── down.sql │ │ └── up.sql └── seeds │ └── default │ └── 001-plans.sql ├── package.json ├── pages ├── _app.tsx ├── _document.tsx ├── account.tsx ├── index.tsx └── signin.tsx ├── pnpm-lock.yaml ├── postcss.config.js ├── public ├── demo.png ├── favicon.ico ├── github.svg ├── nextjs.svg ├── nhost.svg ├── og.png ├── stripe.svg └── vercel.svg ├── styles ├── chrome-bug.css └── main.css ├── tailwind.config.js ├── tsconfig.json ├── types.ts └── utils ├── __generated__ └── graphql.ts ├── graphql-fetcher.ts ├── helpers.ts ├── nhost.ts └── react-query-client.ts /.env.development.example: -------------------------------------------------------------------------------- 1 | NEXT_PUBLIC_NHOST_SUBDOMAIN=localhost 2 | NEXT_PUBLIC_NHOST_REGION= 3 | 4 | # Stripe 5 | NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_123 6 | STRIPE_SECRET_KEY=sk_test_123 7 | STRIPE_WEBHOOK_SECRET=whsec_123 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env.local 29 | .env.development.local 30 | .env.test.local 31 | .env.production.local 32 | 33 | # vercel 34 | .vercel 35 | 36 | # editors 37 | .vscode 38 | 39 | .nhost 40 | .env.development 41 | functions/node_modules -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Vercel, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Next.js Stripe SaaS Starter 2 | 3 | The ultimate starter kit for high-performance SaaS applications. 4 | 5 | ## Features 6 | 7 | - Secure user management and authentication with [Nhost](https://docs.nhost.io/authentication). 8 | - Powerful data access & management tooling on top of PostgreSQL with [Nhost](https://docs.nhost.io/database). 9 | - Integration with [Stripe Checkout](https://stripe.com/docs/payments/checkout) and the [Stripe customer portal](https://stripe.com/docs/billing/subscriptions/customer-portal). 10 | - Automatic syncing of pricing plans and subscription statuses via [Stripe webhooks](https://stripe.com/docs/webhooks). 11 | 12 | ## Features 13 | 14 | - Postgres Database 15 | - GraphQL API 16 | - Magic Link and GitHub Authentication 17 | - Email Templates 18 | - Remote Stripe GraphQL API 19 | - Next.js 20 | - TypeScript 21 | - Tailwind CSS 22 | - GraphQL Codegen with React Query 23 | 24 | ## Demo 25 | 26 | - [https://nextjs-stripe-starter-template.vercel.app/](https://nextjs-stripe-starter-template.vercel.app/) 27 | 28 | [![Screenshot of demo](./public/demo.png)](https://xxx.vercel.app/) 29 | 30 | ## Development Setup 31 | 32 | ### Nhost 33 | 34 | - Clone this repo. 35 | - Copy `.env.local.example` to `.env.development`. 36 | - Add the following environment variables from [Stripe](https://dashboard.stripe.com/test/apikeys) to the `.env.development` file: 37 | - `NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY` 38 | - `STRIPE_SECRET_KEY` 39 | 40 | ### Stripe (test mode) 41 | 42 | - Create 4 products in the [Stripe Dashboard](https://stripe.com/docs/products-prices/getting-started). 43 | - Add the products to the `nhost/seeds/default/001-plans.sql` file. The first time you're starting the Nhost project using `nhost up` the seed script will run and add the data to your `plans` table. 44 | 45 | ### Stripe Webhooks (test mode) 46 | 47 | - Make sure you have the [Stripe CLI](https://stripe.com/docs/stripe-cli) installed. 48 | - Run `pnpm stripe:listen`. 49 | - You'll see an output stating the Webhook signing secret starting with `whsec_`. 50 | - Copy the Webhook signing secret to your `.env.development` for `STRIPE_WEBHOOK_SECRET`. 51 | 52 | ### Frontend and Backend 53 | 54 | - Start the backend with `nhost up`. 55 | - Start the frontend with `pnpm dev`. 56 | 57 | You now have a fully working backend and frontend with Next.js, Nhost, and Stripe. 58 | 59 | ## Go Live 60 | 61 | ### Nhost 62 | 63 | - Add the following [environment variables](https://docs.nhost.io/platform/environment-variables) from [Stripe](https://stripe.com/docs/keys#test-live-modes) (using live mode): 64 | - `STRIPE_SECRET_KEY` 65 | - `STRIPE_WEBHOOK_SECRET` 66 | - Connect your Nhost project to your [Git repository](https://docs.nhost.io/platform/git). 67 | - This will create the tables automatically for you. 68 | 69 | ### Stripe (live mode) 70 | 71 | - Create 4 products in the [Stripe Dashboard](https://stripe.com/docs/products-prices/getting-started) (live mode). 72 | - Add the products to the `plans` Plans database in the Nhost Dashboard. 73 | 74 | ### Stripe Webhooks (live mode) 75 | 76 | - Add a [webhook endpoint in Stripe](https://dashboard.stripe.com/webhooks) pointing to `https://{subdomain}.functions.{region}.nhost.run/v1/webhook/stripe`. 77 | - Configure the events you want to listen to. It's OK to listen to all events. 78 | - Copy the "Signing secret" and add it as an [environment variable](https://docs.nhost.io/platform/environment-variables) in Nhost with the name `STRIPE_WEBHOOK_SECRET`. 79 | 80 | ### Frontend Hosting 81 | 82 | You can use any frontend hosting, like [Vercel](https://vercel.com/) and [Netlify](https://netlify.com/). The process is the same: 83 | 84 | - Connect the repo with a new project in the frontend hosting service. 85 | - Add the following: 86 | - `NEXT_PUBLIC_NHOST_SUBDOMAIN` (from Nhost) 87 | - `NEXT_PUBLIC_NHOST_REGION` (from Nhost) 88 | - `NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY` (from Stripe) 89 | - Retrigger a deployment so the newly added environment variables are applied. 90 | -------------------------------------------------------------------------------- /components/Layout.tsx: -------------------------------------------------------------------------------- 1 | import Head from 'next/head'; 2 | import { useRouter } from 'next/router'; 3 | 4 | import Navbar from 'components/ui/Navbar'; 5 | import Footer from 'components/ui/Footer'; 6 | import { ReactNode } from 'react'; 7 | import { PageMeta } from '../types'; 8 | 9 | interface Props { 10 | children: ReactNode; 11 | meta?: PageMeta; 12 | } 13 | 14 | export default function Layout({ children, meta: pageMeta }: Props) { 15 | const router = useRouter(); 16 | const meta = { 17 | title: 'Next.js Subscription Starter', 18 | description: 'Brought to you by Next.js, Stripe, and Nhost.', 19 | cardImage: '/og.png', 20 | ...pageMeta 21 | }; 22 | 23 | return ( 24 | <> 25 | 26 | {meta.title} 27 | 28 | 29 | 30 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
{children}
47 |