"use client"; import React from "react"; import { useAuth } from "@/contexts/auth-context"; import { useAuthConfig } from "@/hooks/use-auth-config"; import { Button } from "@/components/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { Tooltip, TooltipContent, TooltipTrigger, } from "@/components/ui/tooltip"; import { User, LogOut, Key, Clock } from "lucide-react"; import { getAuthToken, isTokenExpired } from "@/lib/auth"; import { toast } from "sonner"; export function UserMenu() { const { user, logout, isAuthenticated } = useAuth(); const { isAuthConfigured } = useAuthConfig(); const handleCopyToken = async () => { const token = getAuthToken(); if (!token) { toast.error("No authentication token found"); return; } try { await navigator.clipboard.writeText(token); toast.success("API token copied to clipboard"); } catch (error) { toast.error("Failed to copy token to clipboard"); } }; const getTokenExpiryInfo = () => { const token = getAuthToken(); if (!token) return null; try { const payload = JSON.parse(atob(token.split(".")[1])); const exp = payload.exp; if (!exp) return null; const expiryDate = new Date(exp * 1000); const now = new Date(); const hoursRemaining = Math.max( 0, (expiryDate.getTime() - now.getTime()) / (1000 * 60 * 60), ); if (hoursRemaining < 1) { return `Expires in ${Math.round(hoursRemaining * 60)} minutes`; } else if (hoursRemaining < 24) { return `Expires in ${Math.round(hoursRemaining)} hours`; } else { return `Expires in ${Math.round(hoursRemaining / 24)} days`; } } catch { return null; } }; if (!isAuthenticated || !user) { if (!isAuthConfigured) { return ( Sign In Authentication is not configured on this server ); } return ( Sign In ); } return ( {user.avatar_url ? ( ) : ( )} {user.name || user.username} {user.email && ( {user.email} )} Copy API Token {getTokenExpiryInfo() && ( {getTokenExpiryInfo()} )} {user.organizations && user.organizations.length > 0 && ( <> Organizations {user.organizations.map((org) => ( {org} ))} > )} Log out ); }
Authentication is not configured on this server
{user.name || user.username}
{user.email}