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
10 changes: 7 additions & 3 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 Down Expand Up @@ -85,9 +86,12 @@ export function NavUser({ user }: any) {
<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
Copy link

Choose a reason for hiding this comment

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

Selecting the newest subscription record to infer active status can yield incorrect entitlement checks. Filter for an active status when querying instead of relying on recency.

Prompt for AI agents
Address the following comment on convex/subscriptions.ts at line 200:

<comment>Selecting the newest subscription record to infer active status can yield incorrect entitlement checks. Filter for an active status when querying instead of relying on recency.</comment>

<file context>
@@ -194,10 +193,11 @@ export const checkUserSubscriptionStatus = query({
     const subscription = await ctx.db
       .query(&quot;subscriptions&quot;)
       .withIndex(&quot;userId&quot;, (q) =&gt; q.eq(&quot;userId&quot;, user.tokenIdentifier))
+      .order(&quot;desc&quot;)  // Order by createdAt in descending order
       .first();
 
</file context>
Suggested change
.order("desc") // Order by createdAt in descending order
.filter((q) => q.eq(q.field("status"), "active"))

.first();

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