feat: enhance user authentication and profile retrieval

- Updated GET handler in auth route to fetch user UUID from cookie using AuthService.
- Improved error handling for unauthenticated and non-existent users.
- Added team name retrieval for the user profile, with fallback handling.
- Refactored AuthClient to return detailed user information including team details.
- Enhanced navigation component to use a dropdown menu for user actions, improving UI/UX.
- Implemented loading state in UserContext to manage user info fetching.
This commit is contained in:
Julien Froidefond
2025-08-25 16:33:10 +02:00
parent 49804c0fa1
commit 42217c1c13
8 changed files with 517 additions and 39 deletions

View File

@@ -4,7 +4,19 @@ import Link from "next/link";
import { usePathname } from "next/navigation";
import { Button } from "@/components/ui/button";
import { ThemeToggle } from "@/components/layout/theme-toggle";
import { BarChart3, User, Settings, Building2 } from "lucide-react";
import {
BarChart3,
User,
Settings,
Building2,
ChevronDown,
} from "lucide-react";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
interface NavigationProps {
userInfo?: {
@@ -67,22 +79,41 @@ export function Navigation({ userInfo }: NavigationProps = {}) {
<div className="flex items-center space-x-4">
{userInfo && (
<Link
href="/login"
className="flex items-center gap-3 px-3 py-2 rounded-lg bg-muted/50 hover:bg-muted/70 transition-colors cursor-pointer"
>
<div className="w-8 h-8 rounded-full bg-primary/20 border border-primary/30 flex items-center justify-center">
<User className="h-4 w-4 text-primary" />
</div>
<div className="hidden sm:block">
<p className="text-sm font-medium">
{userInfo.firstName} {userInfo.lastName}
</p>
<p className="text-xs text-muted-foreground">
{userInfo.teamName}
</p>
</div>
</Link>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
className="flex items-center gap-3 px-3 py-2 rounded-lg bg-muted/50 hover:bg-muted/70 transition-colors"
>
<div className="w-8 h-8 rounded-full bg-primary/20 border border-primary/30 flex items-center justify-center">
<User className="h-4 w-4 text-primary" />
</div>
<div className="hidden sm:block text-left">
<p className="text-sm font-medium">
{userInfo.firstName} {userInfo.lastName}
</p>
<p className="text-xs text-muted-foreground">
{userInfo.teamName}
</p>
</div>
<ChevronDown className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-56">
<DropdownMenuItem asChild>
<Link href="/account" className="flex items-center gap-2">
<Settings className="h-4 w-4" />
Mon compte
</Link>
</DropdownMenuItem>
<DropdownMenuItem asChild>
<Link href="/login" className="flex items-center gap-2">
<User className="h-4 w-4" />
Se déconnecter
</Link>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)}
<ThemeToggle />
</div>