import { TriangleAlertIcon } from "lucide-react"; import React from "react"; import PasswordInput from "src/components/password/PasswordInput"; import { toast } from "sonner"; import SettingsHeader from "src/components/SettingsHeader"; import { Alert, AlertDescription, AlertTitle } from "src/components/ui/alert"; import { LoadingButton } from "src/components/ui/custom/loading-button"; import { Label } from "src/components/ui/label"; import { useInfo } from "src/hooks/useInfo"; import { request } from "src/utils/request"; export function ChangeUnlockPassword() { const { mutate: refetchInfo } = useInfo(); const [currentUnlockPassword, setCurrentUnlockPassword] = React.useState(""); const [newUnlockPassword, setNewUnlockPassword] = React.useState(""); const [confirmNewUnlockPassword, setConfirmNewUnlockPassword] = React.useState(""); const [loading, setLoading] = React.useState(false); const onSubmit = async (e: React.FormEvent) => { e.preventDefault(); try { if (newUnlockPassword !== confirmNewUnlockPassword) { throw new Error("Password confirmation does not match"); } setLoading(true); await request("/api/unlock-password", { method: "PATCH", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ currentUnlockPassword, newUnlockPassword, }), }); await refetchInfo(); toast("Successfully changed password", { description: "Please start your node with your new password", }); } catch (error) { toast.error("Password change failed", { description: (error as Error).message, }); } finally { setLoading(false); } }; return ( <>
Important! Password can't be reset or recovered. Make sure to back it up!
Change Password
); }