`;
}
private async handleSubmit(e: Event) {
e.preventDefault();
this.error = "";
// Validate passwords match
if (this.password !== this.confirmPassword) {
this.error = "Passwords do not match";
return;
}
// Validate password length
if (this.password.length < 8) {
this.error = "Password must be at least 8 characters";
return;
}
this.isSubmitting = true;
try {
if (!this.email) {
throw new Error("Email not loaded");
}
// Hash password client-side with user's email
const hashedPassword = await hashPasswordClient(
this.password,
this.email,
);
const response = await fetch("/api/auth/reset-password", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token: this.token, password: hashedPassword }),
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.error || "Failed to reset password");
}
// Show success message
this.isSuccess = true;
} catch (err) {
this.error =
err instanceof Error ? err.message : "Failed to reset password";
} finally {
this.isSubmitting = false;
}
}
}