"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { Loader2 } from "lucide-react"; import { toast } from "sonner"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; import { authClient } from "@/lib/auth/auth-client"; export function SettingsClient({ name, email }: { name: string; email: string }) { const router = useRouter(); const [displayName, setDisplayName] = useState(name); const [savingProfile, setSavingProfile] = useState(false); const [savingPw, setSavingPw] = useState(false); async function saveProfile(e: React.FormEvent) { e.preventDefault(); setSavingProfile(true); const { error } = await authClient.updateUser({ name: displayName }); setSavingProfile(false); if (error) toast.error(error.message ?? "Could not update"); else { toast.success("Profile updated"); router.refresh(); } } async function changePassword(e: React.FormEvent) { e.preventDefault(); const form = new FormData(e.currentTarget); setSavingPw(true); const { error } = await authClient.changePassword({ currentPassword: String(form.get("current")), newPassword: String(form.get("new")), revokeOtherSessions: true, }); setSavingPw(false); if (error) toast.error(error.message ?? "Could not change password"); else { toast.success("Password changed"); e.currentTarget.reset(); } } return (
Profile Update your name and see your email.
setDisplayName(e.target.value)} />
Password Change your account password.
); }