import { Input, Button, useToasts } from "@geist-ui/core" import Cookies from "js-cookie" import { useState } from "react" const Password = () => { const [password, setPassword] = useState('') const [newPassword, setNewPassword] = useState('') const [confirmPassword, setConfirmPassword] = useState('') const { setToast } = useToasts() const handlePasswordChange = (e: React.ChangeEvent) => { setPassword(e.target.value) } const handleNewPasswordChange = (e: React.ChangeEvent) => { setNewPassword(e.target.value) } const handleConfirmPasswordChange = (e: React.ChangeEvent) => { setConfirmPassword(e.target.value) } const onSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!password || !newPassword || !confirmPassword) { setToast({ text: "Please fill out all fields", type: "error", }) } if (newPassword !== confirmPassword) { setToast({ text: "New password and confirm password do not match", type: "error", }) } const res = await fetch("/server-api/auth/change-password", { method: "PUT", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${Cookies.get("drift-token")}`, }, body: JSON.stringify({ oldPassword: password, newPassword, }), }) if (res.status === 200) { setToast({ text: "Password updated successfully", type: "success", }) setPassword('') setNewPassword('') setConfirmPassword('') } else { const data = await res.json() setToast({ text: data.error ?? "Failed to update password", type: "error", }) } } return (
) } export default Password