shadcnkit provides a foundation for building applications with subscription-based access control and resource limits.
constants/plans.ts
, this file contains the available subscription plans and their associated resource limits.middlewares/subscriptionCheck.ts
, the middleware checks the user’s subscription and enforces resource limits.app/api
handle CRUD operations for notes and tasks while utilizing the subscription middleware.utils/drizzle/notesTasksFoldersService.ts
file contains functions for interacting with the database, including usage tracking.constants/plans.ts
.PLANS
object with the desired plan name and resource limits.PRICE_ID_TO_PLAN
object, mapping the price ID to the plan name.constants/plans.ts
.PLANS
object, specifying the limit for the new resource.middlewares/subscriptionCheck.ts
.SubscriptionLimits
interface to include the new resource limit.resourceKeyToPlanLimitKey
object to map the new resource key to the corresponding plan limit key.app/api
for your resource (e.g., app/api/newResource/route.ts
).GET
, POST
, PUT
, DELETE
).checkSubscription
middleware and apply it to the route handlers that require subscription checks.utils/drizzle/notesTasksFoldersService.ts
(or create a new service file for your resource).checkSubscription
middleware in middlewares/subscriptionCheck.ts
performs the following steps:
requireAuth
function.getSubscription
function.limits
object, which specifies the resource limits to check.getUsageTracking
function.403 Forbidden
response indicating that the plan limit has been reached.handler
function, passing the user ID.