Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Update better-auth to version 1.2.7 and enhance subscription plan management

Bill Yang67e504a775a9
diff --git a/client/package-lock.json b/client/package-lock.json
index 3b995301c..7ffe8b784 100644
--- a/client/package-lock.json
+++ b/client/package-lock.json
@@ -38,7 +38,7 @@
"@types/country-flag-icons": "^1.2.2",
"@types/three": "^0.175.0",
"@uidotdev/usehooks": "^2.4.1",
- "better-auth": "^1.2.6",
+ "better-auth": "^1.2.7",
"boring-avatars": "^1.11.2",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
diff --git a/client/package.json b/client/package.json
index dcfe1e0fb..7e9a46927 100644
--- a/client/package.json
+++ b/client/package.json
@@ -39,7 +39,7 @@
"@types/country-flag-icons": "^1.2.2",
"@types/three": "^0.175.0",
"@uidotdev/usehooks": "^2.4.1",
- "better-auth": "^1.2.6",
+ "better-auth": "^1.2.7",
"boring-avatars": "^1.11.2",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
diff --git a/client/src/app/settings/subscription/components/ChangePlanDialog.tsx b/client/src/app/settings/subscription/components/ChangePlanDialog.tsx
index 5c8d75d5a..a6bc62b4c 100644
--- a/client/src/app/settings/subscription/components/ChangePlanDialog.tsx
+++ b/client/src/app/settings/subscription/components/ChangePlanDialog.tsx
@@ -12,6 +12,8 @@ import {
import { AlertCircle, Shield } from "lucide-react";
import { useEffect, useState } from "react";
import { Subscription } from "@/api/admin/subscription";
+import { Badge } from "@/components/ui/badge";
+import { cn } from "@/lib/utils";
interface ChangePlanDialogProps {
showUpgradeDialog: boolean;
@@ -38,6 +40,8 @@ export function ChangePlanDialog({
}: ChangePlanDialogProps) {
// State to track if we're resuming a subscription
const [resumingPlan, setResumingPlan] = useState<string | null>(null);
+ // State to track billing interval preference
+ const [isAnnual, setIsAnnual] = useState<boolean>(false);
// When dialog opens and subscription is canceled, highlight the current plan
useEffect(() => {
@@ -47,11 +51,25 @@ export function ChangePlanDialog({
activeSubscription?.plan
) {
setResumingPlan(activeSubscription.plan);
+ // Initialize the annual toggle based on the current subscription
+ setIsAnnual(activeSubscription.plan.includes("-annual"));
+ } else if (showUpgradeDialog && activeSubscription?.plan) {
+ // Initialize the annual toggle based on the current subscription
+ setIsAnnual(activeSubscription.plan.includes("-annual"));
} else {
setResumingPlan(null);
}
}, [showUpgradeDialog, activeSubscription]);
+ // Filter plans based on the selected billing interval
+ const filteredPlans = upgradePlans.filter(
+ (plan) =>
+ plan.name.startsWith("basic") &&
+ (isAnnual
+ ? plan.name.includes("-annual")
+ : !plan.name.includes("-annual"))
+ );
+
return (
<Dialog
open={showUpgradeDialog}
@@ -93,75 +111,111 @@ export function ChangePlanDialog({
</Alert>
)}
+ {/* Billing toggle buttons */}
+ <div className="flex justify-center mb-6">
+ <div className="bg-neutral-100 dark:bg-neutral-800 p-1 rounded-full inline-flex relative">
+ <button
+ onClick={() => setIsAnnual(false)}
+ className={cn(
+ "px-6 py-2 rounded-full text-sm font-medium transition-all",
+ !isAnnual
+ ? "bg-white dark:bg-neutral-700 shadow-sm text-black dark:text-white"
+ : "text-neutral-600 dark:text-neutral-400 hover:text-neutral-900 dark:hover:text-neutral-200"
+ )}
+ >
+ Monthly
+ </button>
+ <div className="relative">
+ <button
+ onClick={() => setIsAnnual(true)}
+ className={cn(
+ "px-6 py-2 rounded-full text-sm font-medium transition-all",
+ isAnnual
+ ? "bg-white dark:bg-neutral-700 shadow-sm text-black dark:text-white"
+ : "text-neutral-600 dark:text-neutral-400 hover:text-neutral-900 dark:hover:text-neutral-200"
+ )}
+ >
+ Annual
+ </button>
+ <Badge className="absolute -top-2 -right-2 bg-emerald-500 text-white border-0 pointer-events-none">
+ 2 months free
+ </Badge>
+ </div>
+ </div>
+ </div>
+
<div className="grid gap-4">
- {/* Basic Plans */}
+ {/* Pro Plans */}
<div>
<h3 className="font-medium mb-3 flex items-center">
<Shield className="h-4 w-4 mr-2 text-green-500" />
- Basic Plans
+ Pro Plans
</h3>
<div className="space-y-3">
- {upgradePlans
- .filter((plan) => plan.name.startsWith("basic"))
- .map((plan) => (
- <Card
- key={plan.priceId}
- className={`cursor-pointer hover:shadow-md transition-shadow ${
- (activeSubscription?.plan === plan.name &&
- !activeSubscription?.cancelAtPeriodEnd) ||
- resumingPlan === plan.name
- ? "ring-2 ring-green-400"
- : ""
- }`}
- >
- <CardContent className="p-3">
- <div className="flex items-center justify-between">
- <div>
- <h3 className="font-bold">
- {plan.limits.events.toLocaleString()} events
- </h3>
- <p className="text-sm text-gray-500 dark:text-gray-400">
- ${plan.price} / {plan.interval}
- </p>
- </div>
- <Button
- size="sm"
- variant={
- (activeSubscription?.plan === plan.name &&
- !activeSubscription?.cancelAtPeriodEnd) ||
- (resumingPlan === plan.name &&
- resumingPlan === activeSubscription?.plan)
- ? "outline"
- : "default"
- }
- onClick={() => {
- if (
- activeSubscription?.plan !== plan.name ||
- activeSubscription?.cancelAtPeriodEnd
- ) {
- handleUpgradeSubscription(plan.name);
- }
- }}
- disabled={
- (activeSubscription?.plan === plan.name &&
- !activeSubscription?.cancelAtPeriodEnd) ||
- isProcessing
- }
- >
- {activeSubscription?.plan === plan.name &&
- !activeSubscription?.cancelAtPeriodEnd
- ? "Current"
- : resumingPlan === plan.name &&
- resumingPlan === activeSubscription?.plan
- ? "Resume"
- : isProcessing
- ? "Processing..."
- : "Select"}
- </Button>
+ {filteredPlans.map((plan) => (
+ <Card
+ key={plan.priceId}
+ className={`cursor-pointer hover:shadow-md transition-shadow ${
+ (activeSubscription?.plan === plan.name &&
+ !activeSubscription?.cancelAtPeriodEnd) ||
+ resumingPlan === plan.name
+ ? "ring-2 ring-green-400"
+ : ""
+ }`}
+ >
+ <CardContent className="p-3">
+ <div className="flex items-center justify-between">
+ <div>
+ <h3 className="font-bold">
+ {plan.limits.events.toLocaleString()} events
+ {isAnnual && (
+ <Badge className="ml-2 bg-emerald-500 text-white border-0 text-xs">
+ Save 17%
+ </Badge>
+ )}
+ </h3>
+ <p className="text-sm text-gray-500 dark:text-gray-400">
+ ${plan.price} / {plan.interval}
+ </p>
</div>
- </CardContent>
- </Card>
- ))}
+ <Button
+ size="sm"
+ variant={
+ (activeSubscription?.plan === plan.name &&
+ !activeSubscription?.cancelAtPeriodEnd) ||
+ (resumingPlan === plan.name &&
+ resumingPlan === activeSubscription?.plan)
+ ? "outline"
+ : "default"
+ }
+ onClick={() => {
+ if (
+ activeSubscription?.plan !== plan.name ||
+ activeSubscription?.cancelAtPeriodEnd
+ ) {
+ handleUpgradeSubscription(plan.name);
+ }
+ }}
+ disabled={
+ (activeSubscription?.plan === plan.name &&
+ !activeSubscription?.cancelAtPeriodEnd) ||
+ isProcessing
+ }
+ >
+ {activeSubscription?.plan === plan.name &&
+ !activeSubscription?.cancelAtPeriodEnd
+ ? "Current"
+ : resumingPlan === plan.name &&
+ resumingPlan === activeSubscription?.plan
+ ? "Resume"
+ : isProcessing
+ ? "Processing..."
+ : "Select"}
+ </Button>
+ </div>
+ </CardContent>
+ </Card>
+ ))}
</div>
</div>
</div>
diff --git a/client/src/app/settings/subscription/page.tsx b/client/src/app/settings/subscription/page.tsx
index c5fe8b80c..2f1c8f0ab 100644
--- a/client/src/app/settings/subscription/page.tsx
+++ b/client/src/app/settings/subscription/page.tsx
@@ -173,20 +173,18 @@ export default function SubscriptionPage() {
const getCurrentTierPrices = () => {
if (!activeSubscription?.plan) return [];
- // Get the current interval
- const currentInterval = isAnnualPlan ? "year" : "month";
-
- // Return all available plans for switching, matching the current interval
- return STRIPE_PRICES.filter((p) => p.interval === currentInterval).sort(
- (a, b) => {
- // First sort by plan type (basic first, then pro)
- if (a.name.startsWith("basic") && b.name.startsWith("pro")) return -1;
- if (a.name.startsWith("pro") && b.name.startsWith("basic")) return 1;
-
- // Then sort by event limit
- return a.limits.events - b.limits.events;
- }
- );
+ // Return all available plans for switching, regardless of interval
+ // The ChangePlanDialog will handle filtering by interval
+ return STRIPE_PRICES.sort((a, b) => {
+ // First sort by plan type (basic only now)
+
+ // Then sort by interval (month first, then year)
+ if (a.interval === "month" && b.interval === "year") return -1;
+ if (a.interval === "year" && b.interval === "month") return 1;
+
+ // Then sort by event limit
+ return a.limits.events - b.limits.events;
+ });
};
const upgradePlans = getCurrentTierPrices();
@@ -229,6 +227,10 @@ export default function SubscriptionPage() {
return `Expires on ${formattedDate}`;
}
+ if (activeSubscription.cancelAtPeriodEnd) {
+ return `Ends on ${formattedDate}`;
+ }
+
return isAnnualPlan
? `Renews annually on ${formattedDate}`
: `Renews monthly on ${formattedDate}`;
@@ -334,9 +336,16 @@ export default function SubscriptionPage() {
Annual
</Badge>
)}
+ {activeSubscription.cancelAtPeriodEnd && (
+ <Badge className="ml-2 bg-orange-500 text-white">
+ Canceling
+ </Badge>
+ )}
</CardTitle>
<CardDescription>
- {activeSubscription.status === "active"
+ {activeSubscription.cancelAtPeriodEnd
+ ? "Your subscription will be canceled at the end of the current billing period."
+ : activeSubscription.status === "active"
? "Your subscription is active."
: activeSubscription.status === "canceled"
? "Your subscription has been canceled but is still active until the end of the billing period."
@@ -375,7 +384,9 @@ export default function SubscriptionPage() {
<h3 className="font-medium">Renewal Date</h3>
<p className="text-lg font-bold">{formatRenewalDate()}</p>
<p className="text-sm text-gray-500 dark:text-gray-400">
- {isAnnualPlan
+ {activeSubscription.cancelAtPeriodEnd
+ ? "Your subscription will not renew after this date"
+ : isAnnualPlan
? "Your plan renews once per year"
: "Your plan renews monthly"}
</p>
@@ -413,14 +424,24 @@ export default function SubscriptionPage() {
</CardContent>
<CardFooter>
{activeSubscription.status === "active" ? (
- <Button
- variant="outline"
- onClick={handleCancelSubscription}
- disabled={isProcessing}
- className="text-red-500 hover:text-red-600"
- >
- {isProcessing ? "Processing..." : "Cancel Subscription"}
- </Button>
+ activeSubscription.cancelAtPeriodEnd ? (
+ <Button
+ onClick={handleResumeSubscription}
+ disabled={isProcessing}
+ className="text-emerald-500 hover:text-emerald-600"
+ >
+ {isProcessing ? "Processing..." : "Resume Subscription"}
+ </Button>
+ ) : (
+ <Button
+ variant="outline"
+ onClick={handleCancelSubscription}
+ disabled={isProcessing}
+ className="text-red-500 hover:text-red-600"
+ >
+ {isProcessing ? "Processing..." : "Cancel Subscription"}
+ </Button>
+ )
) : (
<Button
onClick={handleResumeSubscription}
diff --git a/client/src/app/settings/subscription/utils/planUtils.tsx b/client/src/app/settings/subscription/utils/planUtils.tsx
index b798ea1c5..8d44cb788 100644
--- a/client/src/app/settings/subscription/utils/planUtils.tsx
+++ b/client/src/app/settings/subscription/utils/planUtils.tsx
@@ -41,14 +41,14 @@ export const getPlanDetails = (
},
basic: {
id: "basic",
- name: "Basic",
+ name: "Pro",
price: "$19+",
interval: "month",
- description: "Essential analytics for small projects",
+ description: "Advanced analytics for growing projects",
features: [
- "Core analytics features",
+ "Advanced analytics features",
"14-day data retention",
- "Basic support",
+ "Priority support",
],
color:
"bg-gradient-to-br from-green-50 to-emerald-100 dark:from-green-800 dark:to-emerald-800",
diff --git a/client/src/app/subscribe/page.tsx b/client/src/app/subscribe/page.tsx
index 619b78f7c..b6992c7c3 100644
--- a/client/src/app/subscribe/page.tsx
+++ b/client/src/app/subscribe/page.tsx
@@ -20,7 +20,10 @@ import { cn } from "@/lib/utils";
import { StandardPage } from "../../components/StandardPage";
// Available event tiers for the slider
-const EVENT_TIERS = [20_000, 100_000, 250_000, 500_000, 1_000_000, 2_000_000];
+const EVENT_TIERS = [
+ 20_000, 100_000, 250_000, 500_000, 1_000_000, 2_000_000, 5_000_000,
+ 10_000_000,
+];
// Define types for plans
interface PlanTemplate {
@@ -70,12 +73,12 @@ const PLAN_TEMPLATES: PlanTemplate[] = [
},
{
id: "basic",
- name: "Basic",
- description: "Essential analytics for small projects",
+ name: "Pro",
+ description: "Advanced analytics for growing projects",
baseFeatures: [
- "Core analytics features",
+ "Advanced analytics features",
"14-day data retention",
- "Basic support",
+ "Priority support",
],
color:
"bg-gradient-to-br from-green-50 to-emerald-100 dark:from-green-800 dark:to-emerald-800",
@@ -170,8 +173,12 @@ function getDirectPlanID(
eventSuffix = "500k";
} else if (eventLimit <= 1_000_000) {
eventSuffix = "1m";
- } else {
+ } else if (eventLimit <= 2_000_000) {
eventSuffix = "2m";
+ } else if (eventLimit <= 5_000_000) {
+ eventSuffix = "5m";
+ } else {
+ eventSuffix = "10m";
}
// Construct the plan name with annual suffix if needed
diff --git a/client/src/lib/stripe.ts b/client/src/lib/stripe.ts
index b0dc41ca7..c5e856c82 100644
--- a/client/src/lib/stripe.ts
+++ b/client/src/lib/stripe.ts
@@ -82,11 +82,47 @@ export const STRIPE_PRICES = [
},
{
name: "basic2m-annual",
- priceId: "price_1R1fRMDFVprnAny24AMo0Vuu",
+ priceId: "price_1RE1bQDFVprnAny2ELKQS79d",
price: 990,
interval: "year",
limits: {
events: 2_000_000,
},
},
+ {
+ name: "basic5m",
+ priceId: "price_1R2kybDFVprnAny21Mo1Wjuz",
+ price: 129,
+ interval: "month",
+ limits: {
+ events: 5_000_000,
+ },
+ },
+ {
+ name: "basic5m-annual",
+ priceId: "price_1RE1ebDFVprnAny2BbHtnuko",
+ price: 1290,
+ interval: "year",
+ limits: {
+ events: 5_000_000,
+ },
+ },
+ {
+ name: "basic10m",
+ priceId: "price_1R2kzxDFVprnAny2wdMx2Npp",
+ price: 169,
+ interval: "month",
+ limits: {
+ events: 10_000_000,
+ },
+ },
+ {
+ name: "basic10m-annual",
+ priceId: "price_1RE1fHDFVprnAny2SKY4gFCA",
+ price: 1690,
+ interval: "year",
+ limits: {
+ events: 10_000_000,
+ },
+ },
];
diff --git a/server/package-lock.json b/server/package-lock.json
index 9dc3e3624..14035c35f 100644
--- a/server/package-lock.json
+++ b/server/package-lock.json
@@ -13,7 +13,7 @@
"@fastify/cors": "^10.0.2",
"@fastify/one-line-logger": "^1.4.0",
"@fastify/static": "^8.0.4",
- "better-auth": "^1.2.6",
+ "better-auth": "^1.2.7",
"dotenv": "^16.4.7",
"drizzle-orm": "^0.40.0",
"fastify": "^5.1.0",
diff --git a/server/package.json b/server/package.json
index 0b924a165..b6e8097b0 100644
--- a/server/package.json
+++ b/server/package.json
@@ -21,7 +21,7 @@
"@fastify/cors": "^10.0.2",
"@fastify/one-line-logger": "^1.4.0",
"@fastify/static": "^8.0.4",
- "better-auth": "^1.2.6",
+ "better-auth": "^1.2.7",
"dotenv": "^16.4.7",
"drizzle-orm": "^0.40.0",
"fastify": "^5.1.0",
diff --git a/server/src/lib/const.ts b/server/src/lib/const.ts
index f6714a865..853621c4b 100644
--- a/server/src/lib/const.ts
+++ b/server/src/lib/const.ts
@@ -79,10 +79,42 @@ export const STRIPE_PRICES = [
},
{
name: "basic2m-annual",
- priceId: "price_1R1fRMDFVprnAny24AMo0Vuu",
+ priceId: "price_1RE1bQDFVprnAny2ELKQS79d",
interval: "year",
limits: {
events: 2_000_000,
},
},
+ {
+ name: "basic5m",
+ priceId: "price_1R2kybDFVprnAny21Mo1Wjuz",
+ interval: "month",
+ limits: {
+ events: 5_000_000,
+ },
+ },
+ {
+ name: "basic5m-annual",
+ priceId: "price_1RE1ebDFVprnAny2BbHtnuko",
+ interval: "year",
+ limits: {
+ events: 5_000_000,
+ },
+ },
+ {
+ name: "basic10m",
+ priceId: "price_1R2kzxDFVprnAny2wdMx2Npp",
+ interval: "month",
+ limits: {
+ events: 10_000_000,
+ },
+ },
+ {
+ name: "basic10m-annual",
+ priceId: "price_1RE1fHDFVprnAny2SKY4gFCA",
+ interval: "year",
+ limits: {
+ events: 10_000_000,
+ },
+ },
];