diff options
| author | Fuwn <[email protected]> | 2026-02-10 01:32:16 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-10 01:32:16 -0800 |
| commit | 293f9ccc308b69f507e752af01a49652faee330f (patch) | |
| tree | b699e52309cfab03d539a048de34a98158d6168b /apps/web/lib/hooks | |
| parent | feat: add automatic timeline refresh with scroll position preservation (diff) | |
| download | asa.news-293f9ccc308b69f507e752af01a49652faee330f.tar.xz asa.news-293f9ccc308b69f507e752af01a49652faee330f.zip | |
feat: gate offline reading to pro and developer plans
Service worker now only caches Supabase REST responses when the user's
tier allows offline reading. Client syncs tier status to SW via
postMessage after profile loads. Free users see a descriptive offline
banner instead of stale cached data.
Diffstat (limited to 'apps/web/lib/hooks')
| -rw-r--r-- | apps/web/lib/hooks/use-offline-access-sync.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/apps/web/lib/hooks/use-offline-access-sync.ts b/apps/web/lib/hooks/use-offline-access-sync.ts new file mode 100644 index 0000000..a324d86 --- /dev/null +++ b/apps/web/lib/hooks/use-offline-access-sync.ts @@ -0,0 +1,24 @@ +"use client" + +import { useEffect } from "react" +import { TIER_LIMITS, type SubscriptionTier } from "@asa-news/shared" + +export function useOfflineAccessSync(tier: SubscriptionTier | undefined) { + useEffect(() => { + if (!tier) return + + const allowed = TIER_LIMITS[tier]?.allowsOfflineReading ?? false + + navigator.serviceWorker?.controller?.postMessage({ + type: "SET_OFFLINE_ACCESS", + allowed, + }) + + navigator.serviceWorker?.ready.then((registration) => { + registration.active?.postMessage({ + type: "SET_OFFLINE_ACCESS", + allowed, + }) + }) + }, [tier]) +} |