2026-02-10 11:16:39 +09:00
|
|
|
|
/**
|
2026-02-06 10:43:16 +09:00
|
|
|
|
* @file features/layout/components/user-menu.tsx
|
|
|
|
|
|
* @description 사용자 프로필 드롭다운 메뉴 컴포넌트
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2026-02-05 15:56:41 +09:00
|
|
|
|
"use client";
|
|
|
|
|
|
|
2026-02-10 11:16:39 +09:00
|
|
|
|
import { User } from "@supabase/supabase-js";
|
2026-02-26 09:05:17 +09:00
|
|
|
|
import { LogOut, Settings } from "lucide-react";
|
2026-02-10 11:16:39 +09:00
|
|
|
|
import { useRouter } from "next/navigation";
|
2026-02-05 15:56:41 +09:00
|
|
|
|
import { signout } from "@/features/auth/actions";
|
|
|
|
|
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
|
|
|
|
|
import {
|
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
|
DropdownMenuLabel,
|
|
|
|
|
|
DropdownMenuSeparator,
|
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
|
} from "@/components/ui/dropdown-menu";
|
2026-03-12 09:26:27 +09:00
|
|
|
|
import { KIS_REMEMBER_LOCAL_STORAGE_KEYS } from "@/features/settings/lib/kis-remember-storage";
|
2026-02-10 11:16:39 +09:00
|
|
|
|
import { cn } from "@/lib/utils";
|
2026-02-05 15:56:41 +09:00
|
|
|
|
|
2026-02-12 14:20:07 +09:00
|
|
|
|
const SESSION_RELATED_STORAGE_KEYS = [
|
|
|
|
|
|
"session-storage",
|
|
|
|
|
|
"auth-storage",
|
|
|
|
|
|
"autotrade-kis-runtime-store",
|
2026-03-12 09:26:27 +09:00
|
|
|
|
...KIS_REMEMBER_LOCAL_STORAGE_KEYS,
|
2026-02-12 14:20:07 +09:00
|
|
|
|
] as const;
|
|
|
|
|
|
|
2026-02-05 15:56:41 +09:00
|
|
|
|
interface UserMenuProps {
|
2026-02-06 10:43:16 +09:00
|
|
|
|
/** Supabase User 객체 */
|
2026-02-05 15:56:41 +09:00
|
|
|
|
user: User | null;
|
2026-02-10 11:16:39 +09:00
|
|
|
|
/** 홈 랜딩의 shader 배경 위에서 대비를 높이는 모드 */
|
|
|
|
|
|
blendWithBackground?: boolean;
|
2026-02-05 15:56:41 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-06 10:43:16 +09:00
|
|
|
|
/**
|
2026-02-10 11:16:39 +09:00
|
|
|
|
* 사용자 메뉴/프로필 컴포넌트
|
2026-02-06 10:43:16 +09:00
|
|
|
|
* @param user 로그인한 사용자 정보
|
2026-02-10 11:16:39 +09:00
|
|
|
|
* @param blendWithBackground shader 배경 위 가독성 모드
|
|
|
|
|
|
* @returns Avatar 버튼 + 드롭다운 메뉴
|
|
|
|
|
|
* @see features/layout/components/header.tsx 헤더 우측 액션 영역에서 호출
|
2026-02-06 10:43:16 +09:00
|
|
|
|
*/
|
2026-02-10 11:16:39 +09:00
|
|
|
|
export function UserMenu({ user, blendWithBackground = false }: UserMenuProps) {
|
2026-02-05 15:56:41 +09:00
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
|
|
|
|
if (!user) return null;
|
|
|
|
|
|
|
2026-02-12 14:20:07 +09:00
|
|
|
|
/**
|
|
|
|
|
|
* @description 로그아웃 제출 직전에 세션 관련 로컬 스토리지를 정리합니다.
|
|
|
|
|
|
* @see features/auth/actions.ts signout - 서버 세션 종료를 담당합니다.
|
|
|
|
|
|
*/
|
|
|
|
|
|
const clearSessionRelatedStorage = () => {
|
|
|
|
|
|
if (typeof window === "undefined") return;
|
|
|
|
|
|
|
|
|
|
|
|
for (const key of SESSION_RELATED_STORAGE_KEYS) {
|
|
|
|
|
|
window.localStorage.removeItem(key);
|
2026-02-26 09:05:17 +09:00
|
|
|
|
window.sessionStorage.removeItem(key);
|
2026-02-12 14:20:07 +09:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-02-05 15:56:41 +09:00
|
|
|
|
return (
|
2026-02-06 10:43:16 +09:00
|
|
|
|
<DropdownMenu modal={false}>
|
2026-02-05 15:56:41 +09:00
|
|
|
|
<DropdownMenuTrigger asChild>
|
2026-02-10 11:16:39 +09:00
|
|
|
|
<button
|
|
|
|
|
|
className={cn(
|
|
|
|
|
|
"flex items-center gap-2 rounded-full outline-none transition-colors",
|
|
|
|
|
|
blendWithBackground
|
|
|
|
|
|
? "ring-1 ring-white/30 hover:bg-black/30 focus-visible:ring-2 focus-visible:ring-white/70"
|
|
|
|
|
|
: "",
|
|
|
|
|
|
)}
|
|
|
|
|
|
aria-label="사용자 메뉴 열기"
|
|
|
|
|
|
>
|
|
|
|
|
|
<Avatar className="h-8 w-8 transition-opacity hover:opacity-90">
|
2026-02-05 15:56:41 +09:00
|
|
|
|
<AvatarImage src={user.user_metadata?.avatar_url} />
|
2026-02-10 11:16:39 +09:00
|
|
|
|
<AvatarFallback
|
|
|
|
|
|
className={cn(
|
|
|
|
|
|
"text-xs font-bold text-white",
|
|
|
|
|
|
blendWithBackground
|
|
|
|
|
|
? "bg-brand-500/90 [text-shadow:0_1px_8px_rgba(0,0,0,0.45)]"
|
|
|
|
|
|
: "bg-linear-to-br from-brand-500 to-brand-700",
|
|
|
|
|
|
)}
|
|
|
|
|
|
>
|
2026-02-05 15:56:41 +09:00
|
|
|
|
{user.email?.charAt(0).toUpperCase()}
|
|
|
|
|
|
</AvatarFallback>
|
|
|
|
|
|
</Avatar>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</DropdownMenuTrigger>
|
2026-02-10 11:16:39 +09:00
|
|
|
|
|
2026-02-05 15:56:41 +09:00
|
|
|
|
<DropdownMenuContent align="end" className="w-56">
|
|
|
|
|
|
<DropdownMenuLabel className="font-normal">
|
|
|
|
|
|
<div className="flex flex-col space-y-1">
|
|
|
|
|
|
<p className="text-sm font-medium leading-none">
|
2026-02-10 11:16:39 +09:00
|
|
|
|
{user.user_metadata?.full_name || user.user_metadata?.name || "사용자"}
|
2026-02-05 15:56:41 +09:00
|
|
|
|
</p>
|
2026-02-10 11:16:39 +09:00
|
|
|
|
<p className="text-xs leading-none text-muted-foreground">{user.email}</p>
|
2026-02-05 15:56:41 +09:00
|
|
|
|
</div>
|
|
|
|
|
|
</DropdownMenuLabel>
|
2026-02-10 11:16:39 +09:00
|
|
|
|
|
2026-02-05 15:56:41 +09:00
|
|
|
|
<DropdownMenuSeparator />
|
2026-02-10 11:16:39 +09:00
|
|
|
|
|
2026-02-05 15:56:41 +09:00
|
|
|
|
<DropdownMenuItem onClick={() => router.push("/settings")}>
|
|
|
|
|
|
<Settings className="mr-2 h-4 w-4" />
|
|
|
|
|
|
<span>설정</span>
|
|
|
|
|
|
</DropdownMenuItem>
|
2026-02-10 11:16:39 +09:00
|
|
|
|
|
2026-02-05 15:56:41 +09:00
|
|
|
|
<DropdownMenuSeparator />
|
2026-02-10 11:16:39 +09:00
|
|
|
|
|
2026-02-12 14:20:07 +09:00
|
|
|
|
<form action={signout} onSubmit={clearSessionRelatedStorage}>
|
2026-02-05 15:56:41 +09:00
|
|
|
|
<DropdownMenuItem asChild>
|
|
|
|
|
|
<button className="w-full text-red-600 dark:text-red-400">
|
|
|
|
|
|
<LogOut className="mr-2 h-4 w-4" />
|
|
|
|
|
|
<span>로그아웃</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
|
</form>
|
|
|
|
|
|
</DropdownMenuContent>
|
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|