import { useState, useEffect } from "react"; import { useSearchParams, useNavigate } from "react-router-dom"; import { Loader2, Zap, Users, Check } from "lucide-react"; import { useAuth } from "@/contexts/AuthContext"; import { supabase } from "@/lib/supabase"; import { aethexToast } from "@/lib/aethex-toast"; import Layout from "@/components/Layout"; const PLANS = [ { id: "stream_pro", name: "Stream Pro", price: "$9.99", period: "/mo", icon: Zap, seats: 1, resolution: "1080p60", bitrate: "15 Mbps", features: ["GPU-accelerated stream", "1080p60 quality", "1 guaranteed seat", "Priority over free viewers", "No ads"], }, { id: "stream_team", name: "Stream Team", price: "$24.99", period: "/mo", icon: Users, seats: 4, resolution: "1080p60", bitrate: "15 Mbps", features: ["GPU-accelerated stream", "1080p60 quality", "4 guaranteed seats", "Priority over free viewers", "No ads", "Team management"], highlighted: true, }, ] as const; function StreamSuccess() { const [token, setToken] = useState(""); useEffect(() => { supabase.auth.getSession().then(({ data: { session } }) => { if (session?.access_token) setToken(session.access_token); }); }, []); return ( ✓ SUBSCRIPTION ACTIVE Your GPU stream access is now live. Head back to aethex.live to start playing. LAUNCH STREAM → ); } export default function StreamUpgrade() { const [searchParams] = useSearchParams(); const navigate = useNavigate(); const { user } = useAuth(); const [loading, setLoading] = useState(null); const defaultPlan = searchParams.get("plan") === "stream_team" ? "stream_team" : "stream_pro"; const [selectedPlan, setSelectedPlan] = useState(defaultPlan); async function handleCheckout() { if (!user) { navigate("/login?redirect=/stream/upgrade?plan=" + selectedPlan); return; } setLoading(selectedPlan); try { const { data: { session } } = await supabase.auth.getSession(); const token = session?.access_token; if (!token) throw new Error("Not authenticated"); const res = await fetch("/api/subscriptions/create-checkout", { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` }, body: JSON.stringify({ tier: selectedPlan, successUrl: `${window.location.origin}/stream/upgrade?success=true&plan=${selectedPlan}`, cancelUrl: `${window.location.origin}/stream/upgrade?plan=${selectedPlan}`, }), }); const data = await res.json(); if (!res.ok) throw new Error(data.error || "Checkout failed"); // Pass token back to aethex.live after upgrade if (data.url) { window.location.href = data.url; } } catch (err: any) { aethexToast.error(err.message || "Something went wrong"); } finally { setLoading(null); } } const success = searchParams.get("success") === "true"; if (success) { return ; } return ( STREAM ACCESS Upgrade for guaranteed GPU-accelerated seats on aethex.live. Free slots fill up fast. {PLANS.map((plan) => { const Icon = plan.icon; const isSelected = selectedPlan === plan.id; return ( setSelectedPlan(plan.id)} style={{ width: 260, border: `1px solid ${isSelected ? "#00D4FF" : plan.highlighted ? "#C9A84C" : "#161E38"}`, borderRadius: 3, padding: "24px 20px", background: isSelected ? "rgba(0,212,255,0.06)" : "rgba(8,12,24,0.8)", cursor: "pointer", transition: "border-color .2s, background .2s", position: "relative", }} > {plan.highlighted && ( BEST VALUE )} {plan.name.toUpperCase()} {plan.price} {plan.period} {plan.features.map((f) => ( {f} ))} ); })} {loading ? : null} {loading ? "REDIRECTING..." : "SUBSCRIBE NOW"} Cancel anytime · Secured by Stripe ); }
Your GPU stream access is now live. Head back to aethex.live to start playing.
Upgrade for guaranteed GPU-accelerated seats on aethex.live. Free slots fill up fast.
Cancel anytime · Secured by Stripe