From be0a5c08bf9d1059330ba4f3309b3689ce2fbb8f Mon Sep 17 00:00:00 2001 From: pax2678 Date: Thu, 10 Jul 2025 14:30:25 -0700 Subject: [PATCH 1/4] Update the polarPriceId in Subscription table when subscription is updated in Polar. Select the latest subscription when querying subscription based on userId. --- convex/subscriptions.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/convex/subscriptions.ts b/convex/subscriptions.ts index 41b2d2cc..cac4b3e6 100644 --- a/convex/subscriptions.ts +++ b/convex/subscriptions.ts @@ -185,7 +185,7 @@ export const checkUserSubscriptionStatus = query({ } tokenIdentifier = identity.subject; } - + const user = await ctx.db .query("users") .withIndex("by_token", (q) => q.eq("tokenIdentifier", tokenIdentifier)) @@ -194,10 +194,11 @@ export const checkUserSubscriptionStatus = query({ if (!user) { return { hasActiveSubscription: false }; } - + const subscription = await ctx.db .query("subscriptions") .withIndex("userId", (q) => q.eq("userId", user.tokenIdentifier)) + .order("desc") // Order by createdAt in descending order .first(); const hasActiveSubscription = subscription?.status === "active"; @@ -234,6 +235,7 @@ export const checkUserSubscriptionStatusByClerkId = query({ const subscription = await ctx.db .query("subscriptions") .withIndex("userId", (q) => q.eq("userId", user.tokenIdentifier)) + .order("desc") // Order by createdAt in descending order .first(); const hasActiveSubscription = subscription?.status === "active"; @@ -261,6 +263,7 @@ export const fetchUserSubscription = query({ const subscription = await ctx.db .query("subscriptions") .withIndex("userId", (q) => q.eq("userId", user.tokenIdentifier)) + .order("desc") // Order by createdAt in descending order .first(); return subscription; @@ -328,6 +331,7 @@ export const handleWebhookEvent = mutation({ if (existingSub) { await ctx.db.patch(existingSub._id, { + polarPriceId: args.body.data.price_id, amount: args.body.data.amount, status: args.body.data.status, currentPeriodStart: new Date( From 22ef41e922f072f45252cca0238b4c38bc01a287 Mon Sep 17 00:00:00 2001 From: pax2678 Date: Mon, 18 Aug 2025 20:14:54 -0700 Subject: [PATCH 2/4] fix inconsistent priceId value in metadata stored in Polar and Convex. priceId is not updated after a user changes the subscription creating confusion. Changes Summary: Checkout Creation (lines 52-54): - REMOVED: priceId: productPriceId, from the metadata object - RESULT: Metadata now only contains userId when creating Polar checkouts Impact: - Polar subscriptions: Will only store userId in metadata (no priceId) - Convex subscriptions: Will only store userId in metadata (no priceId) - Price tracking: Still works via the polarPriceId field in the subscription record - User linking: Preserved via userId in metadata for webhook processing --- convex/subscriptions.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/convex/subscriptions.ts b/convex/subscriptions.ts index cac4b3e6..7cc76747 100644 --- a/convex/subscriptions.ts +++ b/convex/subscriptions.ts @@ -51,7 +51,6 @@ const createCheckout = async ({ customerEmail: customerEmail, metadata: { ...metadata, - priceId: productPriceId, }, }; From 0cf77d6e3b88c73581d91a2527323d78b27e4810 Mon Sep 17 00:00:00 2001 From: pax2678 Date: Mon, 1 Sep 2025 18:18:43 -0700 Subject: [PATCH 3/4] fix: clean up dashboard settings navigation and remove duplicate links Changes Made: - Removed duplicate Settings link from sidebar navigation - Eliminated redundant Settings entry in navSecondary array in app-sidebar.tsx - Fixed Settings link in user dropdown navigation - Added proper routing to Settings dropdown item in nav-user.tsx - Settings link now navigates to /dashboard/settings when clicked - Used asChild pattern with React Router Link for proper navigation Result: - Eliminates confusing duplicate Settings links in dashboard - Provides single, functional Settings access through user dropdown - Improves user experience with cleaner navigation structure --- app/components/dashboard/app-sidebar.tsx | 8 +------- app/components/dashboard/nav-user.tsx | 10 +++++++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/app/components/dashboard/app-sidebar.tsx b/app/components/dashboard/app-sidebar.tsx index 1708ba19..f552ae62 100644 --- a/app/components/dashboard/app-sidebar.tsx +++ b/app/components/dashboard/app-sidebar.tsx @@ -26,13 +26,7 @@ const data = { icon: MessageCircle, }, ], - navSecondary: [ - { - title: "Settings", - url: "/dashboard/settings", - icon: IconSettings, - }, - ], + navSecondary: [], }; export function AppSidebar({ diff --git a/app/components/dashboard/nav-user.tsx b/app/components/dashboard/nav-user.tsx index 3ded4859..25e1177f 100644 --- a/app/components/dashboard/nav-user.tsx +++ b/app/components/dashboard/nav-user.tsx @@ -5,6 +5,7 @@ import { IconUserCircle, } from "@tabler/icons-react"; import { SettingsIcon } from "lucide-react"; +import { Link } from "react-router"; import { Avatar, AvatarFallback, AvatarImage } from "~/components/ui/avatar"; import { DropdownMenu, @@ -85,9 +86,12 @@ export function NavUser({ user }: any) { Account - - - Settings + + + + + Settings + From b1bdb4b8f57f98bc9d0276f667ba1bb531b529de Mon Sep 17 00:00:00 2001 From: pax2678 Date: Mon, 1 Sep 2025 19:30:39 -0700 Subject: [PATCH 4/4] fix: account link in dashboard user drop down MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "Account" link in the dashboard user dropdown will use Clerk's openUserProfile() function, which is exactly the same mechanism that the homepage "Manage account" link uses through the UserButton component. Summary of Changes: Updated app/components/dashboard/nav-user.tsx: 1. Added openUserProfile import from useClerk hook 2. Added click handler to Account dropdown item that calls openUserProfile() Result: - ✅ Dashboard Account link now opens Clerk's UserProfile modal (same as homepage "Manage account") - ✅ Consistent behavior between homepage and dashboard user account access - ✅ Uses Clerk's native functionality rather than custom routing Now when users click "Account" in the dashboard user dropdown, it will open the same Clerk Account Profile page that appears when clicking "Manage account" from the homepage user button dropdown. --- app/components/dashboard/nav-user.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/components/dashboard/nav-user.tsx b/app/components/dashboard/nav-user.tsx index 25e1177f..d6a5966d 100644 --- a/app/components/dashboard/nav-user.tsx +++ b/app/components/dashboard/nav-user.tsx @@ -32,7 +32,7 @@ export function NavUser({ user }: any) { (user?.firstName?.charAt(0) || "").toUpperCase() + (user?.lastName?.charAt(0) || "").toUpperCase(); const userProfile = user.imageUrl; - const { signOut } = useClerk(); + const { signOut, openUserProfile } = useClerk(); return ( @@ -82,7 +82,7 @@ export function NavUser({ user }: any) { - + openUserProfile()}> Account