UPDATE: Now checks for token on url to extract.

This commit is contained in:
EvanLin3141
2025-02-06 15:44:20 +00:00
parent af71f63873
commit 00d627a1e2
2 changed files with 34 additions and 11 deletions

View File

@@ -15,9 +15,10 @@ interface ResetPasswordErrors {
interface SubmitProps { interface SubmitProps {
onSubmit: () => void; onSubmit: () => void;
token: string;
} }
const PasswordResetForm: React.FC<SubmitProps> = ({ onSubmit }) => { const PasswordResetForm: React.FC<SubmitProps> = ({ onSubmit, token }) => {
const [errors, setErrors] = useState<ResetPasswordErrors>({}); const [errors, setErrors] = useState<ResetPasswordErrors>({});
@@ -63,7 +64,7 @@ const PasswordResetForm: React.FC<SubmitProps> = ({ onSubmit }) => {
if (validateResetForm()) { if (validateResetForm()) {
try { try {
const response = await fetch("/user/reset_password/<string:token>/<string:confirmNewPassword>", { const response = await fetch("/user/reset_password/<string:${token}", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",

View File

@@ -1,15 +1,37 @@
import React from 'react'; import React from "react";
import PasswordResetForm from '../components/Auth/PasswordResetForm'; import PasswordResetForm from "../components/Auth/PasswordResetForm";
import { useParams, useNavigate } from "react-router-dom";
const ForgotPasswordPage: React.FC = () => { const ForgotPasswordPage: React.FC = () => {
const doNothing = (): void => {}; const { token } = useParams<{ token: string }>();
const navigate = useNavigate();
return ( // If the token is missing, handle the error (e.g., redirect or show a message)
<div className="flex flex-col items-center justify-center h-screen"> if (!token) {
<h1 className="text-2xl font-bold mb-4">Forgot Password</h1> return (
<PasswordResetForm onSubmit={doNothing} /> <div className="flex flex-col items-center justify-center h-screen">
</div> <h1 className="text-2xl font-bold mb-4">Invalid Token</h1>
); <p className="text-red-500">The reset token is missing or invalid.</p>
<button
onClick={() => navigate("/login")}
className="text-blue-500 underline mt-4"
>
Go back to Login
</button>
</div>
);
}
const handlePasswordReset = () => {
};
return (
<div className="flex flex-col items-center justify-center h-screen">
<h1 className="text-2xl font-bold mb-4">Forgot Password</h1>
<PasswordResetForm onSubmit={handlePasswordReset} token={token} />
</div>
);
}; };
export default ForgotPasswordPage; export default ForgotPasswordPage;