Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import type { PlanId } from "./shared-auth";
export interface PlanPermissions {
maxSnapshots: number;
cloudBackup: boolean;
advancedDetection: boolean;
customRules: boolean;
teamSharing: boolean;
}
const PLAN_CONFIG: Record<PlanId, PlanPermissions> = {
free: {
maxSnapshots: 100,
cloudBackup: false,
advancedDetection: false,
customRules: false,
teamSharing: false,
},
pro: {
maxSnapshots: 1000,
cloudBackup: true,
advancedDetection: true,
customRules: false,
teamSharing: false,
},
team: {
maxSnapshots: 5000,
cloudBackup: true,
advancedDetection: true,
customRules: true,
teamSharing: true,
},
enterprise: {
maxSnapshots: 999999,
cloudBackup: true,
advancedDetection: true,
customRules: true,
teamSharing: true,
},
};
export function getPlanPermissions(plan: PlanId): PlanPermissions {
return PLAN_CONFIG[plan];
}
/**
* Single source of truth for where the plan comes from.
* Reads Better Auth user shape.
*/
export function mapUserToPlan(user: any): PlanId {
if (user?.subscription?.plan) {
return user.subscription.plan as PlanId;
}
if (user?.metadata?.plan) {
return user.metadata.plan as PlanId;
}
return "free";
}
|