"use client" import { useState, useEffect, useRef } from "react" import { User, Shield, Link as LinkIcon } from "lucide-react" import { SettingsProfileTab } from "@/components/profile/settings-profile-tab" import { SettingsSecurityTab } from "@/components/profile/settings-security-tab" import { SettingsAccountsTab } from "@/components/profile/settings-accounts-tab" interface AuthMethods { hasPassword: boolean passkeyCount: number oauthProviders: Array<{ providerId: string; id: string }> totalAuthMethods: number } type SettingsSubTab = "profile" | "security" | "accounts" const subTabs: { id: SettingsSubTab; label: string; icon: typeof User }[] = [ { id: "profile", label: "Profile", icon: User }, { id: "security", label: "Security", icon: Shield }, { id: "accounts", label: "Linked Accounts", icon: LinkIcon }, ] interface SettingsContainerProps { name: string email: string role: string | null createdAt: string } export function SettingsContainer({ name, email, role, createdAt }: SettingsContainerProps) { const [activeSubTab, setActiveSubTab] = useState("profile") const [authMethods, setAuthMethods] = useState(null) const [isLoadingAuthMethods, setIsLoadingAuthMethods] = useState(true) const fetchRef = useRef(false) useEffect(() => { if (fetchRef.current) return fetchRef.current = true let cancelled = false fetch("/api/user/me/auth-methods", { credentials: "include" }) .then(r => r.ok ? r.json() : null) .then(data => { if (cancelled) return if (data) setAuthMethods(data) setIsLoadingAuthMethods(false) }) .catch(() => { setIsLoadingAuthMethods(false) }) return () => { cancelled = true } }, []) const refreshAuthMethods = async () => { try { const res = await fetch("/api/user/me/auth-methods", { credentials: "include" }) if (res.ok) setAuthMethods(await res.json()) } catch { // silently fail } } return (
{/* Sidebar Navigation */} {/* Content Area */}
{activeSubTab === "profile" && ( )} {activeSubTab === "security" && ( )} {activeSubTab === "accounts" && ( )}
) }