Skip to content

Commit 3eabe92

Browse files
committed
feat(header): Enhance mobile navigation with user actions and logout functionality
- Add dashboard link to mobile menu for authenticated users - Implement logout functionality with Supabase auth signOut method - Refactor mobile menu user section to include dashboard and logout options - Add Shield and LogOut icons for improved visual navigation - Remove redundant UserIcon and UserDisplay in mobile menu - Improve mobile menu user experience with more actionable items
1 parent 6a1bf51 commit 3eabe92

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

components/header.tsx

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import { useState, useEffect } from "react"
66
import { Button } from "@/components/ui/button"
77
// import { ThemeToggle } from "@/components/theme-toggle"
88
import { UserIcon } from "@/components/user-icon"
9-
import { Menu, X } from "lucide-react"
9+
import { Menu, X, Shield, LogOut } from "lucide-react"
1010
import { useAuth } from "@/lib/hooks/useAuth"
11+
import { createClient } from "@/lib/supabase/client"
12+
import { useRouter } from "next/navigation"
1113
import CodeuniaLogo from "./codeunia-logo";
1214
import dynamic from "next/dynamic";
1315

@@ -25,7 +27,16 @@ const UserDisplay = dynamic(() => import("./UserDisplay"), {
2527
export default function Header() {
2628
const [isMenuOpen, setIsMenuOpen] = useState(false)
2729
const pathname = usePathname()
30+
const router = useRouter()
2831
const { user, loading } = useAuth()
32+
const supabase = createClient()
33+
34+
const handleLogout = async () => {
35+
await supabase.auth.signOut()
36+
setIsMenuOpen(false)
37+
router.push("/")
38+
router.refresh()
39+
}
2940

3041
// Close mobile menu when clicking outside
3142
useEffect(() => {
@@ -126,10 +137,7 @@ export default function Header() {
126137
<div className="flex md:hidden items-center space-x-1">
127138
{/* <ThemeToggle /> */}
128139
{!loading && user && (
129-
<div className="flex items-center space-x-1">
130-
<PremiumButton user={user} compact />
131-
<UserIcon />
132-
</div>
140+
<PremiumButton user={user} compact />
133141
)}
134142
<Button
135143
variant="ghost"
@@ -195,13 +203,25 @@ export default function Header() {
195203

196204
{/* User Actions */}
197205
{!loading && user && (
198-
<div className="pt-3 mt-3 border-t border-border">
199-
<div className="flex items-center space-x-2 py-2 px-3">
200-
<UserIcon />
201-
<div className="flex-1 min-w-0">
202-
<UserDisplay userId={user.id} showCodeuniaId={false} />
203-
</div>
204-
</div>
206+
<div className="pt-3 mt-3 border-t border-border space-y-1">
207+
{/* Dashboard Link */}
208+
<Link
209+
href="/protected"
210+
className="flex items-center space-x-2 text-sm font-medium transition-colors py-2.5 px-3 rounded-md text-foreground hover:text-primary hover:bg-muted/50"
211+
onClick={() => setIsMenuOpen(false)}
212+
>
213+
<Shield className="h-4 w-4" />
214+
<span>Dashboard</span>
215+
</Link>
216+
217+
{/* Logout Button */}
218+
<button
219+
onClick={handleLogout}
220+
className="flex items-center space-x-2 text-sm font-medium transition-colors py-2.5 px-3 rounded-md text-red-600 hover:text-red-700 hover:bg-red-50 dark:hover:bg-red-950/20 w-full text-left"
221+
>
222+
<LogOut className="h-4 w-4" />
223+
<span>Log out</span>
224+
</button>
205225
</div>
206226
)}
207227

0 commit comments

Comments
 (0)