-
Install deps
pnpm i # or npm/yarn -
Copy envs
cp .env.local.example .env.local cp functions/.env.example functions/.env # Fill Firebase client keys and Stripe test keys + price IDs -
Start local dev (3 terminals)
pnpm emulators pnpm dev pnpm stripe:listen
-
Try the flow
- Visit /login → sign up
- Go to /pricing → choose Pro Monthly
- Pay with 4242 4242 4242 4242
- Redirect to /dashboard → see plan & dates
- Firestore users/ updated; Stripe CLI shows webhooks
- Change Firebase project once in package.json → config.project
- Prices: set STRIPE_PRICE_* in functions/.env
- Add a new plan:
- functions/src/plans.server.ts → add key
- lib/planCatalog.ts → add label
- health: GET /asia-south1/health → { ok: true, stripe: boolean }
- stripeWebhook: signature-verified
- createCheckoutSession: uses plan code → env price id
- billingPortal: manage subscription
The firestore.rules file ensures users can only access their own documents in /users/{userId}. Deploy with:
firebase deploy --only firestore:rules- Uses
pnpm stripe:listenforwarding to /stripeWebhook - Note on replacing STRIPE_WEBHOOK_SECRET when using "stripe listen"
- Assumptions :
- user isn't signed up, so we make him signup
- initially user is in the free plan ( didnt show it on ui, was showing, but messed it a bit later)
- only upon successful transcation is the firestore entry is updated with a pro plan with plan details
- Plans are fixed in env
- Minimal ui : generated by gpt, refiened + refactored it a little - Trade-offs :
- didnt store the plans in db, instead stored in env
- rest of the things below are gpt generated :
- Firestore user plans update only via Stripe webhook events, so, firestore may lag for a few seconds after checkout.
- Firestore rules are minimal (user can only read/write own doc).
- No advanced error handling- make sure you run the last 3 scripts one after the other.
- make sure you have configured your credentials properly
- make sure to have added firestore rules
- 403 on Firestore: deploy rules or sign in
- 400 on checkout: missing STRIPE_PRICE_* env
- No webhook events: stripe listen not running / wrong secret
- CORS/URL issues: check NEXT_PUBLIC_FUNCTIONS_URL and APP_URL
pnpm emulatorspnpm devpnpm stripe:listenpnpm build:functionspnpm deploy:functions