Skip to content

Fix License Management: auth middleware bug, Sidebar integration, and upgrade flow#29

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/implement-license-management
Draft

Fix License Management: auth middleware bug, Sidebar integration, and upgrade flow#29
Copilot wants to merge 2 commits into
mainfrom
copilot/implement-license-management

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 1, 2026

License management was broken in multiple ways: the auth middleware had a falsy-check bug that caused incorrect behavior for free users with free_usage === 0 and made unnecessary Clerk API calls on every premium request; the Sidebar component (with plan display) was never mounted; and free users had no in-app path to upgrade.

Server

  • middlewares/auth.js: Replace user.privateMetadata.free_usage (falsy on 0) with ?? 0. Remove the updateUserMetadata call from the else branch — premium users no longer trigger a metadata write on every request.
// Before: 0 is falsy → else fires, resets counter + wasteful API call
if (!hasPremiumPlan && user.privateMetadata.free_usage) { ... }

// After: nullish coalescing correctly handles 0, undefined, null
if (!hasPremiumPlan) {
    req.free_usage = user.privateMetadata.free_usage ?? 0;
} else {
    req.free_usage = 0; // no updateUserMetadata call
}

Client

  • Layout.jsx: Mount Sidebar alongside the outlet; manage sidebar open/close state here; add a mobile backdrop overlay.
  • Sidebar.jsx: Add PRO badges on premium-only nav items (shown to free users only via Clerk <Protect>); add a Manage Plan nav link.
  • Navbar.jsx: Accept optional setSidebar prop — hamburger toggles the Sidebar when in the AI section instead of the inline dropdown.
  • pages/ManagePlan.jsx (new): Dedicated /ai/manage-plan route rendering Clerk's <PricingTable> alongside the user's current plan, giving free users a direct upgrade path from within the app.
  • App.jsx: Register the manage-plan route.

Copilot AI linked an issue Apr 1, 2026 that may be closed by this pull request
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
visible-server Ready Ready Preview, Comment Apr 1, 2026 6:55pm
visiblekai Ready Ready Preview, Comment Apr 1, 2026 6:55pm

- Fix auth middleware: use `?? 0` for free_usage instead of falsy check that incorrectly reset counter; remove unnecessary updateUserMetadata call for premium users
- Add ManagePlan page with Clerk PricingTable for in-app plan management
- Add /ai/manage-plan route in App.jsx
- Integrate Sidebar into Layout with sidebar state and mobile overlay
- Enhance Sidebar with PRO badges on premium-only features and Manage Plan link
- Update Navbar to accept setSidebar prop for toggling Sidebar on mobile
- Add test for manage-plan route

Agent-Logs-Url: https://github.com/VisibleNasir/VisibleKAi/sessions/bd9958b4-90b2-4991-a9a3-95b3a0742cea

Co-authored-by: VisibleNasir <109416738+VisibleNasir@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix license management implementation issue Fix License Management: auth middleware bug, Sidebar integration, and upgrade flow Apr 1, 2026
Copilot AI requested a review from VisibleNasir April 1, 2026 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

License Management implementation

2 participants