"use client"; import { fetchWithAuth } from "@/lib/apiClient"; import { useState } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Lock } from "lucide-react"; export default function PasswordPage() { const [currentPassword, setCurrentPassword] = useState(""); const [newPassword, setNewPassword] = useState(""); const [confirmPassword, setConfirmPassword] = useState(""); const [passwordSaving, setPasswordSaving] = useState(false); const handleChangePassword = async () => { if (newPassword !== confirmPassword) { alert("New passwords do not match."); return; } setPasswordSaving(true); try { const res = await fetchWithAuth("/api/auth/change-password", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ current_password: currentPassword, new_password: newPassword, }), }); const data = await res.json(); if (res.ok) { alert(data.message || "Password updated successfully!"); setCurrentPassword(""); setNewPassword(""); setConfirmPassword(""); } else { alert("Failed to change password: " + (data.detail || "Unknown error")); } } catch (err) { console.error(err); alert("Network error. Could not change password."); } finally { setPasswordSaving(false); } }; return (
Update your account password securely.