1
- import {
2
- Menu ,
3
- DollarSign ,
4
- LogIn ,
5
- BarChart2 ,
6
- BookHeart ,
7
- User ,
8
- Bot ,
9
- } from 'lucide-react'
1
+ import { Menu , DollarSign , BookHeart , Bot } from 'lucide-react'
10
2
import Image from 'next/image'
11
3
import Link from 'next/link'
12
- import { getServerSession } from 'next-auth '
4
+ import dynamic from 'next/dynamic '
13
5
14
- import { UserDropdown } from './user-dropdown'
15
6
import { Button } from '../ui/button'
16
7
import {
17
8
DropdownMenu ,
@@ -21,12 +12,47 @@ import {
21
12
} from '../ui/dropdown-menu'
22
13
import { Icons } from '../icons'
23
14
24
- import { authOptions } from '@/app/api/auth/[...nextauth]/auth-options'
25
- import { cn } from '@/lib/utils'
15
+ // TODO: This dynamic pattern might not be the best way to handle the navbar. Reconsider from first principles.
16
+
17
+ // Dynamically import client auth components to prevent SSR and enable SSG
18
+ const ClientAuthNav = dynamic (
19
+ ( ) =>
20
+ import ( './client-auth-nav' ) . then ( ( mod ) => ( { default : mod . ClientAuthNav } ) ) ,
21
+ {
22
+ ssr : false ,
23
+ loading : ( ) => < div className = "w-[50px] h-[40px]" /> , // Placeholder to prevent layout shift
24
+ }
25
+ )
26
+
27
+ const ClientUsageLink = dynamic (
28
+ ( ) =>
29
+ import ( './client-auth-nav' ) . then ( ( mod ) => ( {
30
+ default : mod . ClientUsageLink ,
31
+ } ) ) ,
32
+ {
33
+ ssr : false ,
34
+ }
35
+ )
36
+
37
+ const ClientMobileUsageLink = dynamic (
38
+ ( ) =>
39
+ import ( './client-auth-nav' ) . then ( ( mod ) => ( {
40
+ default : mod . ClientMobileUsageLink ,
41
+ } ) ) ,
42
+ {
43
+ ssr : false ,
44
+ }
45
+ )
26
46
27
- export const Navbar = async ( ) => {
28
- const session = await getServerSession ( authOptions )
47
+ const ClientMobileAuthNav = dynamic (
48
+ ( ) =>
49
+ import ( './client-auth-nav' ) . then ( ( mod ) => ( { default : mod . ClientAuthNav } ) ) ,
50
+ {
51
+ ssr : false ,
52
+ }
53
+ )
29
54
55
+ export const Navbar = ( ) => {
30
56
return (
31
57
< header className = "container mx-auto p-4 flex justify-between items-center relative z-10" >
32
58
< Link
@@ -71,15 +97,9 @@ export const Navbar = async () => {
71
97
< Bot className = "h-4 w-4" />
72
98
Agent Store
73
99
</ Link >
74
-
75
- { session && (
76
- < Link
77
- href = "/usage"
78
- 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"
79
- >
80
- Usage
81
- </ Link >
82
- ) }
100
+ < div className = "min-w-[50px] flex items-center" >
101
+ < ClientUsageLink />
102
+ </ div >
83
103
</ nav >
84
104
< div className = "flex items-center space-x-3" >
85
105
< DropdownMenu >
@@ -119,43 +139,13 @@ export const Navbar = async () => {
119
139
Agent Store
120
140
</ Link >
121
141
</ DropdownMenuItem >
122
-
123
- { session && (
124
- < DropdownMenuItem asChild >
125
- < Link href = "/usage" className = "flex items-center" >
126
- < BarChart2 className = "mr-2 h-4 w-4" />
127
- Usage
128
- </ Link >
129
- </ DropdownMenuItem >
130
- ) }
131
- { ! session && (
132
- < DropdownMenuItem asChild >
133
- < Link href = "/login" className = "flex items-center" >
134
- < LogIn className = "mr-2 h-4 w-4" />
135
- Log in
136
- </ Link >
137
- </ DropdownMenuItem >
138
- ) }
142
+ < ClientMobileUsageLink />
143
+ < ClientMobileAuthNav isMobile />
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
- ) }
154
- >
155
- Log in
156
- </ Button >
157
- </ Link >
158
- ) }
146
+ < div className = "min-w-[50px] h-[44px] flex items-center justify-end -ml-3" >
147
+ < ClientAuthNav />
148
+ </ div >
159
149
{ /* <ThemeSwitcher /> */ }
160
150
</ div >
161
151
</ header >
0 commit comments