Improve billing and access control by adding creator subscription check; update route components to enforce user authentication before viewing streams and replays.

This commit is contained in:
Nikita
2025-12-24 17:14:01 -08:00
parent 9d7ea0ada1
commit f81affe448
4 changed files with 64 additions and 8 deletions

View File

@@ -2,7 +2,7 @@ import { createFileRoute } from "@tanstack/react-router"
import { and, desc, eq } from "drizzle-orm"
import { db } from "@/db/connection"
import { getAuth } from "@/lib/auth"
import { hasActiveSubscription } from "@/lib/billing"
import { hasCreatorSubscription } from "@/lib/billing"
import { stream_replays, users } from "@/db/schema"
const json = (data: unknown, status = 200) =>
@@ -56,7 +56,7 @@ const handleGet = async ({
}
}
// Non-owners need subscription to view replays
// Non-owners need subscription to this creator to view replays
if (!session?.user?.id) {
return json(
{ error: "Subscription required", code: "SUBSCRIPTION_REQUIRED" },
@@ -64,7 +64,7 @@ const handleGet = async ({
)
}
const hasSubscription = await hasActiveSubscription(session.user.id)
const hasSubscription = await hasCreatorSubscription(session.user.id, user.id)
if (!hasSubscription) {
return json(
{ error: "Subscription required", code: "SUBSCRIPTION_REQUIRED" },