feat: auth foundation, similar tools, costs, redundancy, anonymous voting

This commit is contained in:
root
2026-07-29 21:59:29 +02:00
parent 8b3b7c9955
commit 59badeaa48
22 changed files with 793 additions and 15 deletions
@@ -0,0 +1,26 @@
import { type Request, type Response, type NextFunction } from "express";
const TIER_FEATURES: Record<string, string[]> = {
free: ["browse", "rate", "search"],
premium: ["browse", "rate", "search", "similar-tools", "costs", "redundancy", "analytics-advanced"],
enterprise: ["browse", "rate", "search", "similar-tools", "costs", "redundancy", "analytics-advanced", "sso", "audit-export", "api-access"],
};
export function hasFeature(tier: string | undefined, feature: string): boolean {
const features = TIER_FEATURES[tier ?? "free"] ?? TIER_FEATURES.free;
return features.includes(feature);
}
export function requireFeature(feature: string) {
return (req: Request, res: Response, next: NextFunction): void => {
if (!req.session.user) {
res.status(401).json({ error: "Authentication required" });
return;
}
if (!hasFeature(req.session.user.tier, feature)) {
res.status(403).json({ error: `Feature "${feature}" requires a higher tier` });
return;
}
next();
};
}