Skip to documentation
Design system / Sources & standards
Current repository source
authButton.tsx
src/components/navigation/authButton.tsx
This view contains the escaped source read during the deployment build. Code and policy text are unchanged. Markdown is shown as source, not rendered as a document. A new deployment refreshes the content.
"use client";
import Link from "next/link";
import { useState } from "react";
import { UserRound } from "lucide-react";
import { cn } from "@/lib/utils";
import { buttonVariants } from "@/components/ui/button";
import { ColorModeMenuItems } from "@/components/colorMode/colorModeMenuItems";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdownMenu";
export type AuthButtonProps = {
isAuthenticated: boolean;
signInHref: string;
signOutHref: string;
userDisplayName?: string;
userEmail?: string;
className?: string;
/** Placement of the shared icon-only account menu. */
presentation?: "topbar" | "sidebar";
};
export function AuthButton({
isAuthenticated,
signInHref,
signOutHref,
userDisplayName,
userEmail,
className,
presentation = "topbar",
}: AuthButtonProps) {
const [container, setContainer] = useState<HTMLDivElement | null>(null);
const sidebar = presentation === "sidebar";
if (!isAuthenticated) {
return (
<Link
href={signInHref}
className={cn(buttonVariants({ variant: "outline", size: "sm" }), className)}
>
Sign in
</Link>
);
}
const menu = (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<button
type="button"
aria-label={userDisplayName?.trim() || "Account"}
className={cn(
"flex min-h-11 cursor-pointer items-center rounded-md py-1.5 text-md transition-colors hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
"min-w-11 justify-center px-2",
className,
)}
>
<span aria-hidden className="flex size-7 shrink-0 items-center justify-center rounded-full bg-muted text-muted-foreground"><UserRound className="size-4" /></span>
</button>
</DropdownMenuTrigger>
<DropdownMenuContent align={sidebar ? "start" : "end"} side={sidebar ? "top" : "bottom"} container={container} className="max-w-[calc(100vw-3.2rem)]">
<DropdownMenuLabel>
<div className="flex flex-col">
<span className="break-all">{userDisplayName ?? "Account"}</span>
{userEmail && (
<span className="break-all text-supporting font-normal text-muted-foreground">{userEmail}</span>
)}
</div>
</DropdownMenuLabel>
<DropdownMenuSeparator />
<ColorModeMenuItems />
<DropdownMenuSeparator />
<DropdownMenuItem asChild>
<a href={signOutHref}>Sign out</a>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
return <div ref={setContainer} className="min-w-0">{menu}</div>;
}
All sources and standards