"use client"; import { authClient } from "@lib/auth"; import { useAuth } from "@lib/auth-context"; import { fetchConnectionsFeature, fetchMemoriesFeature, fetchSubscriptionStatus, } from "@lib/queries"; import { Button } from "@repo/ui/components/button"; import { HeadingH3Bold } from "@repo/ui/text/heading/heading-h3-bold"; import { useCustomer } from "autumn-js/react"; import { CheckCircle, CreditCard, LoaderIcon, LogOut, User, X, } from "lucide-react"; import { motion } from "motion/react"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import { useState } from "react"; import { analytics } from "@/lib/analytics"; export function ProfileView() { const router = useRouter(); const pathname = usePathname(); const { user: session, org } = useAuth(); const organizations = org; const autumn = useCustomer(); const [isLoading, setIsLoading] = useState(false); const { data: memoriesCheck } = fetchMemoriesFeature(autumn as any); const memoriesUsed = memoriesCheck?.usage ?? 0; const memoriesLimit = memoriesCheck?.included_usage ?? 0; const { data: connectionsCheck } = fetchConnectionsFeature(autumn as any); const connectionsUsed = connectionsCheck?.usage ?? 0; // Fetch subscription status with React Query const { data: status = { consumer_pro: null, }, isLoading: isCheckingStatus, } = fetchSubscriptionStatus(autumn as any); const isPro = status.consumer_pro; const handleLogout = () => { analytics.userSignedOut(); authClient.signOut(); router.push("/login"); }; const handleUpgrade = async () => { setIsLoading(true); try { await autumn.attach({ productId: "consumer_pro", successUrl: "https://app.supermemory.ai/", }); window.location.reload(); } catch (error) { console.error(error); setIsLoading(false); } }; // Handle manage billing const handleManageBilling = async () => { await autumn.openBillingPortal({ returnUrl: "https://app.supermemory.ai", }); }; if (session?.isAnonymous) { return (

Sign in to access your profile and billing

); } return (
{/* Profile Section */}

{session?.email}

Logged in

{/* Billing Section */}
{isPro ? "Pro Plan" : "Free Plan"} {isPro && ( Active )}

{isPro ? "Expanded memory capacity" : "Basic plan"}

{/* Usage Stats */}
Memories = memoriesLimit ? "text-red-400" : "text-white/90"}`} > {memoriesUsed} / {memoriesLimit}
= memoriesLimit ? "bg-red-500" : isPro ? "bg-green-500" : "bg-blue-500" }`} style={{ width: `${Math.min((memoriesUsed / memoriesLimit) * 100, 100)}%`, }} />
{isPro && (
Connections {connectionsUsed} / 10
)} {/* Billing Actions */}
{isPro ? ( ) : ( )}
{/* Plan Comparison - Only show for free users */} {!isPro && (
Upgrade to Pro
{/* Free Plan */}

Free Plan

  • 200 memories
  • No connections
  • Basic search
{/* Pro Plan */}

Pro Plan Recommended

  • 5000 memories
  • 10 connections
  • Advanced search
  • Priority support

$15/month (only for first 100 users) • Cancel anytime. No questions asked.

)}
); }