1
+ 'use client'
2
+
1
3
import {
2
4
Menu ,
3
5
DollarSign ,
4
6
LogIn ,
5
7
BarChart2 ,
6
8
BookHeart ,
7
- User ,
8
9
Bot ,
9
10
} from 'lucide-react'
10
11
import Image from 'next/image'
11
12
import Link from 'next/link'
12
- import { getServerSession } from 'next-auth'
13
+ import { useSession } from 'next-auth/react'
14
+
15
+ import { cn } from '@/lib/utils'
13
16
14
17
import { UserDropdown } from './user-dropdown'
18
+ import { Icons } from '../icons'
15
19
import { Button } from '../ui/button'
16
20
import {
17
21
DropdownMenu ,
18
22
DropdownMenuContent ,
19
23
DropdownMenuItem ,
20
24
DropdownMenuTrigger ,
21
25
} from '../ui/dropdown-menu'
22
- import { Icons } from '../icons'
23
26
24
- import { authOptions } from '@/app/api/auth/[...nextauth]/auth-options'
25
- import { cn } from '@/lib/utils'
27
+ export const Navbar = ( ) => {
28
+ const { data : session , status } = useSession ( )
26
29
27
- export const Navbar = async ( ) => {
28
- const session = await getServerSession ( authOptions )
30
+ // Don't render auth-dependent content during loading to prevent hydration mismatch
31
+ const isSessionReady = status !== 'loading'
29
32
30
33
return (
31
34
< header className = "container mx-auto p-4 flex justify-between items-center relative z-10" >
@@ -72,7 +75,8 @@ export const Navbar = async () => {
72
75
Agent Store
73
76
</ Link >
74
77
75
- { session && (
78
+ { /* Only show Usage link when session is ready and user is authenticated */ }
79
+ { isSessionReady && session && (
76
80
< Link
77
81
href = "/usage"
78
82
className = "hover:text-blue-400 transition-colors font-medium px-2 py-1 rounded-md hover:bg-blue-50 dark:hover:bg-blue-900/20"
@@ -120,15 +124,16 @@ export const Navbar = async () => {
120
124
</ Link >
121
125
</ DropdownMenuItem >
122
126
123
- { session && (
127
+ { /* Only show Usage and Login links when session is ready */ }
128
+ { isSessionReady && session && (
124
129
< DropdownMenuItem asChild >
125
130
< Link href = "/usage" className = "flex items-center" >
126
131
< BarChart2 className = "mr-2 h-4 w-4" />
127
132
Usage
128
133
</ Link >
129
134
</ DropdownMenuItem >
130
135
) }
131
- { ! session && (
136
+ { isSessionReady && ! session && (
132
137
< DropdownMenuItem asChild >
133
138
< Link href = "/login" className = "flex items-center" >
134
139
< LogIn className = "mr-2 h-4 w-4" />
@@ -138,24 +143,30 @@ export const Navbar = async () => {
138
143
) }
139
144
</ DropdownMenuContent >
140
145
</ DropdownMenu >
141
- { session ? (
142
- < UserDropdown session = { session } />
143
- ) : (
144
- < Link href = "/login" className = "hidden md:inline-block relative group" >
145
- < div className = "absolute inset-0 bg-[rgb(255,110,11)] translate-x-0.5 -translate-y-0.5" />
146
- < Button
147
- className = { cn (
148
- 'relative' ,
149
- 'bg-white text-black hover:bg-white' ,
150
- 'border border-white/50' ,
151
- 'transition-all duration-300' ,
152
- 'group-hover:-translate-x-0.5 group-hover:translate-y-0.5'
153
- ) }
146
+
147
+ { /* Authentication section - only render when session is ready */ }
148
+ { isSessionReady &&
149
+ ( session ? (
150
+ < UserDropdown session = { session } />
151
+ ) : (
152
+ < Link
153
+ href = "/login"
154
+ className = "hidden md:inline-block relative group"
154
155
>
155
- Log in
156
- </ Button >
157
- </ Link >
158
- ) }
156
+ < div className = "absolute inset-0 bg-[rgb(255,110,11)] translate-x-0.5 -translate-y-0.5" />
157
+ < Button
158
+ className = { cn (
159
+ 'relative' ,
160
+ 'bg-white text-black hover:bg-white' ,
161
+ 'border border-white/50' ,
162
+ 'transition-all duration-300' ,
163
+ 'group-hover:-translate-x-0.5 group-hover:translate-y-0.5'
164
+ ) }
165
+ >
166
+ Log in
167
+ </ Button >
168
+ </ Link >
169
+ ) ) }
159
170
{ /* <ThemeSwitcher /> */ }
160
171
</ div >
161
172
</ header >
0 commit comments