Set up an early gated feature access as a precursor to implementing real Stripe. Admin can assign a role and access time to users. For now we will just have 'free' and 'pro' which prevent and allow project creation respectively. We can use this model and add 'entitlements' later which can do more fine grain feature access per tier. We want to focus on the concept of 'access control' rather than 'specific subscription tiers'.
// Entitlement preset example as what could be added later (not within this issue scope) and also quotas (numeric limits on entitlements)
const TIER_PRESETS = {
free: {
maxProjects: 0,
maxCollaboratorsPerProject: 0,
maxStorageMbPerProject: 0
},
pro: {
maxProjects: 3,
maxCollaboratorsPerProject: 4,
maxStorageMbPerProject: 500
},
unlimited: {
maxProjects: null,
maxCollaboratorsPerProject: null,
maxStorageMbPerProject: null
}
};
// Then we can gate features like this later without worrying about deciding what tiers or features we want to gate
// Determine if a user can create a project
function canCreateProject(user, currentProjectCount) {
const sub = user.subscription;
// Step 1: must have access
if (!sub || sub.status !== 'active') return false;
if (sub.current_period_end && sub.current_period_end < new Date()) return false;
// Step 2: enforce feature limit
const maxProjects = sub.entitlements?.maxProjects ?? null;
if (maxProjects === null) return true; // unlimited
return currentProjectCount < maxProjects;
}
Set up an early gated feature access as a precursor to implementing real Stripe. Admin can assign a role and access time to users. For now we will just have 'free' and 'pro' which prevent and allow project creation respectively. We can use this model and add 'entitlements' later which can do more fine grain feature access per tier. We want to focus on the concept of 'access control' rather than 'specific subscription tiers'.