Skip to content

Commit 55d039e

Browse files
committed
fix: TopNav shows actual tier from backend + complete useUserUsage type
Bug: TopNav read tier from session.user_metadata.tier (stale JWT). When admin bumps a user to Enterprise, the JWT doesn't update until re-login. So TopNav still showed 'Free Plan' even after upgrade. Fix: TopNav now uses useUserUsage hook (GET /users/usage) which reads the actual tier from user_profiles table. Changes reflect immediately after admin dashboard tier update. Also: added repositories and features to useUserUsage return type to match the actual backend response shape.
1 parent cb61792 commit 55d039e

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

frontend/src/components/dashboard/TopNav.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Link } from 'react-router-dom'
22
import { useAuth } from '../../contexts/AuthContext'
3-
import { TIER_FUNCTION_LIMITS, type TierName } from '../../config/api'
3+
import { useUserUsage } from '../../hooks/useCachedQuery'
44
import { Menu, Search, Github, Sun, Moon, LogOut, Settings, BookOpen, ExternalLink } from 'lucide-react'
55
import { useTheme } from 'next-themes'
66
import { Button } from '@/components/ui/button'
@@ -25,9 +25,9 @@ export function TopNav({ onToggleSidebar, sidebarCollapsed, onOpenCommandPalette
2525

2626
const userEmail = session?.user?.email || 'User'
2727
const userInitial = userEmail.charAt(0).toUpperCase()
28-
const rawTier = session?.user?.user_metadata?.tier as string
29-
const userTier: TierName = rawTier && rawTier in TIER_FUNCTION_LIMITS ? (rawTier as TierName) : 'free'
30-
const tierLabel = `${userTier.charAt(0).toUpperCase()}${userTier.slice(1)} Plan`
28+
const { data: usage } = useUserUsage(session?.access_token, session?.user?.id)
29+
const tier = usage?.tier || 'free'
30+
const tierLabel = `${tier.charAt(0).toUpperCase()}${tier.slice(1)} Plan`
3131

3232
const toggleTheme = () => {
3333
setTheme(theme === 'dark' ? 'light' : 'dark')

frontend/src/hooks/useCachedQuery.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,20 @@ export function useUserUsage(apiKey: string | undefined, userId?: string) {
199199
const data = await fetchWithAuth(`${API_URL}/users/usage`, apiKey!)
200200
return data as {
201201
tier: string
202+
repositories: {
203+
current: number
204+
limit: number
205+
display: string
206+
}
202207
limits: {
203208
max_files_per_repo: number
204209
max_functions_per_repo: number
205210
playground_searches_per_day: number | null
206211
}
212+
features: {
213+
priority_indexing: boolean
214+
mcp_access: boolean
215+
}
207216
}
208217
},
209218
enabled: !!apiKey,

0 commit comments

Comments
 (0)