feat(examples): add subscription paywall (Next.js) example (#354)#360
feat(examples): add subscription paywall (Next.js) example (#354)#360Ipramking wants to merge 1 commit into
Conversation
|
@Ipramking is attempting to deploy a commit to the miracle656's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Ipramking Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
️✅ There are no secrets present in this pull request anymore.If these secrets were true positive and are still valid, we highly recommend you to revoke them. 🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request. |
b6de639 to
5984f1b
Compare
A recurring on-chain subscription paywall built on invisible-wallet-sdk. - /paywall "Unlock" creates a recurring payment authorization via wallet.approve(merchant, token, price, expiry) — a Soroban allowance with an expiry, confirmed with the user's passkey. - Subscription status is read from chain (get_allowance simulation) both on the server (lib/subscription.ts, used by the API route and middleware) and on the client. - Free routes (/ , /paywall) vs paid route (/premium). middleware.ts gates /premium on subscription status; the /premium server component re-verifies from chain. The Edge middleware stays SDK-free and defers the chain read to a Node route handler. Verified: tsc --noEmit, next lint, and next build all pass. Closes Miracle656#354
5984f1b to
3313e15
Compare
Summary
Implements #354 — Subscription paywall (Next.js): a new
examples/subscription-paywall/app demonstrating a recurring on-chain subscription paywall built oninvisible-wallet-sdk.How the subscription works
The subscription is a Soroban token allowance from the user's wallet contract to a merchant address, with an expiry:
wallet.approve(feePayer, merchant, token, price, expiry)priceuntilexpiry— the recurring payment authorization, confirmed with the user's passkey.get_allowance(merchant, token)(read-only simulation)Because the status is a read-only simulation it works on the client (
useInvisibleWallet().getAllowance) and the server (lib/subscription.ts) alike.Routes
//paywall/premiummiddleware.ts; server component re-verifies from chain/api/subscriptionmiddleware.tsmatches/premium/:path*, reads the wallet cookie, asks the Node/api/subscriptionroute (which reads the on-chain allowance), and redirects to/paywallwhen inactive — keeping the Stellar SDK out of the Edge runtime. It fails closed on read errors.Acceptance criteria
/+/paywallopen;/premiumgated by middleware + a server-side re-check.get_allowancesimulated against the wallet contract (server inlib/subscription.ts, client via the SDK).Verification
Built against a locally-compiled
sdk/dist.tsc --noEmit,next lint, andnext buildall pass (6 routes generated). Follows the conventions of the existingexamples/nextjs.Set
NEXT_PUBLIC_MERCHANT_ADDRESSin.env.localto run — see the example README.Closes #354