1- import React from "react" ;
2- import { headers } from "next/headers" ;
3- import { auth } from "@/lib/auth-config" ;
1+ "use client" ;
2+
43import { ThemeToggle } from "@/components/navigation/theme-toggle" ;
54import { homeTabs } from "@/constants" ;
65import Logo from "@/components/Logo" ;
76import Link from "next/link" ;
87import { Button } from "@/components/ui/button" ;
98import { Avatar , AvatarFallback , AvatarImage } from "@/components/ui/avatar" ;
109import { config } from "@/lib/config" ;
10+ import {
11+ DropdownMenu ,
12+ DropdownMenuContent ,
13+ DropdownMenuGroup ,
14+ DropdownMenuItem ,
15+ DropdownMenuLabel ,
16+ DropdownMenuSeparator ,
17+ DropdownMenuTrigger ,
18+ } from "@/components/ui/dropdown-menu" ;
19+ import {
20+ IconCreditCard ,
21+ IconDotsVertical ,
22+ IconLogout ,
23+ IconNotification ,
24+ IconUserCircle ,
25+ } from "@tabler/icons-react" ;
26+ import { authClient , useSession } from "@/lib/auth-client" ;
27+ import { useRouter } from "next/navigation" ;
1128
12- const Navbar = async ( ) => {
13- const session = await auth . api . getSession ( {
14- headers : await headers ( ) ,
15- } ) ;
29+ const Navbar = ( ) => {
30+ const { data : session } = useSession ( ) ;
31+ const router = useRouter ( ) ;
1632 const user = session ?. user ;
1733
34+ const handleSignOut = async ( ) => {
35+ await authClient . signOut ( {
36+ fetchOptions : {
37+ onSuccess : ( ) => {
38+ router . push ( config . SIGN_IN ) ;
39+ } ,
40+ } ,
41+ } ) ;
42+ } ;
43+
1844 return (
19- < div className = "sticky z-50 top-0 flex items-center justify-between w-full px-4 sm:px-8 py-2 xl:py-4 bg-gradient -to-r from-black/50 to-gray-700/50 dark:from-black/10 dark:to-black/20 backdrop-blur-lg border-b border-gray-200 dark:border-gray-700" >
45+ < div className = "sticky z-50 top-0 flex items-center justify-between w-full px-4 sm:px-8 py-2 xl:py-4 bg-linear -to-r from-black/50 to-gray-700/50 dark:from-black/10 dark:to-black/20 backdrop-blur-lg border-b border-gray-200 dark:border-gray-700" >
2046 < Logo />
2147 < div >
2248 < ul className = "hidden sm:flex gap-4 text-lg sm:text-base font-semibold text-slate-900 dark:text-white" >
@@ -41,17 +67,71 @@ const Navbar = async () => {
4167 Dashboard
4268 </ Button >
4369 </ Link >
44- < Link href = "/subscriptions" className = "hidden sm:block" >
45- < Button variant = "outline" className = "text-sm sm:text-base" >
46- My Subscriptions
47- </ Button >
48- </ Link >
49- < Avatar className = "h-8 w-8" >
50- < AvatarImage src = { user . image || undefined } alt = { user . name } />
51- < AvatarFallback >
52- { user . name ?. charAt ( 0 ) . toUpperCase ( ) || "U" }
53- </ AvatarFallback >
54- </ Avatar >
70+ < DropdownMenu >
71+ < DropdownMenuTrigger >
72+ < Avatar className = "h-8 w-8 rounded-full" >
73+ < AvatarImage
74+ src = {
75+ user . image ||
76+ `https://ui-avatars.com/api/?name=${ user . name } &size=75`
77+ }
78+ alt = { user . name }
79+ className = "rounded-full"
80+ height = { 75 }
81+ width = { 75 }
82+ />
83+ < AvatarFallback className = "rounded-lg" > CN</ AvatarFallback >
84+ </ Avatar >
85+ </ DropdownMenuTrigger >
86+ < DropdownMenuContent
87+ className = "w-(--radix-dropdown-menu-trigger-width) min-w-56 rounded-lg"
88+ side = { "bottom" }
89+ align = "end"
90+ sideOffset = { 4 }
91+ >
92+ < DropdownMenuLabel className = "p-0 font-normal" >
93+ < div className = "flex items-center gap-2 px-1 py-1.5 text-left text-sm" >
94+ < Avatar className = "h-8 w-8 rounded-lg" >
95+ < AvatarImage
96+ src = {
97+ user . image ||
98+ `https://ui-avatars.com/api/?name=${ user . name } &size=75`
99+ }
100+ alt = { user . name }
101+ />
102+ < AvatarFallback className = "rounded-lg" > CN</ AvatarFallback >
103+ </ Avatar >
104+ < div className = "grid flex-1 text-left text-sm leading-tight" >
105+ < span className = "truncate font-medium" > { user . name } </ span >
106+ < span className = "text-muted-foreground truncate text-xs" >
107+ { user . email }
108+ </ span >
109+ </ div >
110+ </ div >
111+ </ DropdownMenuLabel >
112+ < DropdownMenuSeparator />
113+ < DropdownMenuGroup >
114+ < DropdownMenuItem >
115+ < IconUserCircle />
116+ Account
117+ </ DropdownMenuItem >
118+ < DropdownMenuItem >
119+ < IconCreditCard />
120+ Billing
121+ </ DropdownMenuItem >
122+ < DropdownMenuItem >
123+ < IconNotification />
124+ Notifications
125+ </ DropdownMenuItem >
126+ </ DropdownMenuGroup >
127+ < DropdownMenuSeparator />
128+ < DropdownMenuItem onClick = { ( ) => handleSignOut ( ) } >
129+ < IconLogout />
130+ Log Out
131+ </ DropdownMenuItem >
132+ </ DropdownMenuContent >
133+ { /* </DropdownMenuContent> */ }
134+ </ DropdownMenu >
55135 </ div >
56136 ) : (
57137 < div className = "flex items-center gap-2 sm:gap-4" >
0 commit comments