feat: wire frontend pages to tRPC APIs
- Add hooks (useAuth, useSubscription, useNotifications) for real API data - Add auth service (login/signup) with password hashing and session support - Replace stub auth with real tRPC calls in login/signup/onboarding pages - Replace mock dashboard data with real API data from hooks - Create service pages: DarkWatch, VoicePrint, SpamShield, HomeTitle, RemoveBrokers, Settings - Update Navbar, TopBar, Sidebar with real user data and correct routes - Add passwordHash field to users schema for credential auth - Fix tests to work with real hooks (mock tRPC/hooks)
This commit is contained in:
32
web/src/hooks/useSubscription.ts
Normal file
32
web/src/hooks/useSubscription.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { createResource } from "solid-js";
|
||||
import { api } from "~/lib/api";
|
||||
|
||||
const FEATURE_TIERS: Record<string, string> = {
|
||||
darkwatch_realtime: "premium",
|
||||
voiceprint_batch: "plus",
|
||||
hometitle_scan: "plus",
|
||||
removebrokers_unlimited: "premium",
|
||||
};
|
||||
|
||||
const TIER_ORDER = ["free", "basic", "plus", "premium"];
|
||||
|
||||
export function useSubscription() {
|
||||
const [subscription] = createResource(() =>
|
||||
api.billing.getSubscription.query(),
|
||||
);
|
||||
|
||||
const tier = () => subscription()?.tier ?? "free";
|
||||
|
||||
const hasFeature = (feature: string) => {
|
||||
const requiredTier = FEATURE_TIERS[feature];
|
||||
if (!requiredTier) return true;
|
||||
return TIER_ORDER.indexOf(tier()) >= TIER_ORDER.indexOf(requiredTier);
|
||||
};
|
||||
|
||||
return {
|
||||
subscription,
|
||||
tier,
|
||||
isLoading: subscription.loading,
|
||||
hasFeature,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user