Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions app/components/dashboard/app-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ const data = {
icon: MessageCircle,
},
],
navSecondary: [
{
title: "Settings",
url: "/dashboard/settings",
icon: IconSettings,
},
],
navSecondary: [],
};

export function AppSidebar({
Expand Down
14 changes: 9 additions & 5 deletions app/components/dashboard/nav-user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -31,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 (
<SidebarMenu>
Expand Down Expand Up @@ -81,13 +82,16 @@ export function NavUser({ user }: any) {
</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<DropdownMenuItem>
<DropdownMenuItem onClick={() => openUserProfile()}>
<IconUserCircle />
Account
</DropdownMenuItem>
<DropdownMenuItem>
<SettingsIcon />
Settings
<DropdownMenuItem asChild>
<Link to="/dashboard/settings">

<SettingsIcon />
Settings
</Link>
</DropdownMenuItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
Expand Down
9 changes: 6 additions & 3 deletions convex/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ const createCheckout = async ({
customerEmail: customerEmail,
metadata: {
...metadata,
priceId: productPriceId,
},
};

Expand Down Expand Up @@ -185,7 +184,7 @@ export const checkUserSubscriptionStatus = query({
}
tokenIdentifier = identity.subject;
}

const user = await ctx.db
.query("users")
.withIndex("by_token", (q) => q.eq("tokenIdentifier", tokenIdentifier))
Expand All @@ -194,10 +193,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();
Comment on lines +200 to 201
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Ordering semantics: clarify and confirm index support

.order("desc") on a Convex query orders by the index’s natural order (commonly _creationTime), not a createdAt field. The inline comment is misleading; also confirm the subscriptions table/index supports ordering with this query shape to avoid runtime errors.

-      .order("desc")  // Order by createdAt in descending order
+      .order("desc")  // Order by _creationTime in descending order (latest first)

Optionally verify schema/indexes with the script below.


🏁 Script executed:

#!/bin/bash
# Show subscriptions table indexes
rg -n -C3 'defineTable\(|\.index\(' convex | rg -n -C3 'subscriptions|userId|polarId|by_token'
# Locate schema definitions
fd -a schema -t f convex | xargs -I{} rg -n -C4 'subscriptions|index\(' {}

Length of output: 1952


Clarify ordering semantics on subscriptions query

File: convex/subscriptions.ts (lines 200–201)

-      .order("desc")  // Order by createdAt in descending order
+      .order("desc")  // Order by _creationTime in descending order (latest first)

The subscriptions table doesn’t define a createdAt field; .order() defaults to the internal _creationTime index.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
.order("desc") // Order by createdAt in descending order
.first();
.order("desc") // Order by _creationTime in descending order (latest first)
.first();
🤖 Prompt for AI Agents
In convex/subscriptions.ts around lines 200–201, the call .order("desc") is
misleading because there is no createdAt field on the subscriptions table and
Convex will use the internal _creationTime by default; explicitly specify the
index by replacing the ambiguous ordering with .order("_creationTime", "desc")
and update the inline comment to state that ordering is by the internal
_creationTime (or alternatively add a createdAt column to the subscriptions
schema and order by that if you prefer a public timestamp).


const hasActiveSubscription = subscription?.status === "active";
Expand Down Expand Up @@ -234,6 +234,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";
Expand Down Expand Up @@ -261,6 +262,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;
Expand Down Expand Up @@ -328,6 +330,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(
Expand Down